Comments (4)
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.
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.
@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.
@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)
- Mongoose is not ORM HOT 3
- Mongoose is not ORM HOT 1
- *New topic suggestion: "Asynchronous Programming in Nodejs"* HOT 1
- chapter 11 youtube link broken
- Suggestion for chapter: Security
- chapt 1 prototypal typo
- chapter 3 test error
- ch 2 - Routes in Express.js
- Replace Derby example
- Replace Grunt example
- NEW TOPICS HOT 31
- Tech review all chapters HOT 4
- Change Everyauth to Passport HOT 2
- Remove Express 4 references and Express 3 examples
- Invalid Display URL HOT 1
- serverless examples use outdated dynamodb-doc HOT 1
- Missing routes and api in different chapters HOT 1
- Suggestion: Leading zeros at folders
- Proposal: Remove the request package as alternative.
- invalid path
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from practicalnode.