What does WriteResult ({"nInserted": 1}) mean in MongoDB?

I inserted a document into the mongoDB collection and received a message WriteResult({ "nInserted" : 1 })

db.myColl1.insert({title: 'MongoDB Overview', description: 'MongoDB is no sql database',by: 'tutorials point',url: 'http://www.tutorialspoint.com',tags: ['mongodb', 'database', 'NoSQL'],likes: 100})
WriteResult({ "nInserted" : 1 })

What does it mean WriteResult({ "nInserted" : 1 })?

+4
source share
4 answers

This is the expected behavior of MongoDB. Try using find or findOne to see the inserted object in the collection.

db.myColl1.find({title: 'MongoDB Overview'});

or

db.myColl1.findOne({title: 'MongoDB Overview'});

Normally findOne returns an object with a better format than find, but you can use pretty at the end of the search operation to get a better format.

db.myColl1.find().pretty()
+2
source

What does WriteResult ({"nInserted": 1}) mean?

Whenever you write to the database, you get a WriteResult object that tells us whether the operation was successful or not.

nInserted .

+2

, . :

    db.myColl1.find()

.

+1
source

The commands that are written to the database (save, insert, update, delete, etc.) return the writeResult object so that the application can find out if the document was written correctly and can execute various logic based on the results.

0
source

Source: https://habr.com/ru/post/1538210/


All Articles