Answer the question
In order to leave comments, you need to log in
Error while working with MongoDB?
Hello!
MongoDB version 3.0.7
I just started learning MongoDB and immediately ran into a problem.
There is this simple code:
var MongoClient = require('mongodb').MongoClient;
MongoClient.connect('mongodb://localhost:27017/mongotest',
function(err, db) {
console.log('Connected to MongoDB!');
// using the db connection object, save the collection 'testing' to
// a separate variable:
var collection = db.collection('testing');
// isert a new item using the collection's insert function:
collection.insert({
'title': 'Snowcrash'
}, function(err, docs) {
console.log(docs.length + ' record inserted.');
console.log(docs[0].title + ' – ' + docs[0]._id);
db.close();
});
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question