Giter Site home page Giter Site logo

Comments (4)

josevillacreses avatar josevillacreses commented on May 5, 2024

I got it working with a few changes:

var mongoskin = require('mongoskin'),
dbHost = '127.0.0.1',
dbPort = 27017;

var db = mongoskin.db('mongodb://' + dbHost + ':' + dbPort + '/local', {safe: true});

db.bind('messages').bind({
findOneAndAddText: function (text, fn) {
db.collection('messages').findOne({}, function (error, item) {
if (error) {
console.error(error);
process.exit(1);
}
console.info("findOne: ", item);
item.text = text;
var id = item._id.toString(); // we can store ID in a string
console.info("before saving: ", item);
db.collection('messages').save(item, function (error, count) {
console.info("save: ", count);
return fn(count, id);
});
})
}
});

db.messages.findOneAndAddText('hi', function (count, id) {
db.collection('messages').find({
_id: mongoskin.helper.toObjectID(id)
}).toArray(function (error, items) {
console.info("find: ", items);
db.close();
process.exit(0);
});
});

from practicalnode.

nonacosa avatar nonacosa commented on May 5, 2024

HI,Im CHINA In ch5
node mongo-native-insert.js

db state: connected
{ [MongoError: driver is incompatible with this server version] name: 'MongoError' }

what to do?

my MongoDB -v : db version v3.2.6

from practicalnode.

azat-co avatar azat-co commented on May 5, 2024

@nikolaygit @josevillacreses yes. mongoskin changed the way methods are created. bind().bind() will work. I updated it in new edition's code https://github.com/azat-co/practicalnode/blob/master/code/ch5/mongo-examples/mongo-skin.js

from practicalnode.

azat-co avatar azat-co commented on May 5, 2024

@pkwenda maybe mongodb (npm module) version? check the new code at https://github.com/azat-co/practicalnode/blob/master/code/ch5/mongo-examples/mongo-native-insert.js after you install proper versions with npm i

from practicalnode.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.