Question

How to insert document in collection name contain dot notation?

For Ex: collection: blog and blog. post Insert: db.blog.insert("document"); how to insert in 2nd collection?

Was it helpful?

Solution

Have you tried

db.blog.post.insert({ /* document */ }); 

?

Keep in mind that such a notation doesn't have any different semantics for mongodb, the collection name blog.post doesn't mean the collection is in any way related to the blog collection, i.e. it doesn't make a difference whether you name your collection blog.post or blog_post or simply posts.

This notation is, however, used by MongoDB for its GridFS implementation which by default writes to db.fs.files and db.fs.chunks.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top