简体   繁体   中英

creating and querying a collection in another collection. mongodb node.js

Is there a way to create and query a collection thats inside another collection... Can any one direct me to literature that can teach me how to do this? I've checked the mongodb docs tutorial and i havent come across this scenario No code example because i don't know where to start.

Here is what im trying to do.

Im modelling an online shop. So shop object details are in a collection holding many shops. Now each shop has got products and each product its own unique details. I want to a void using references and rather append but from tutorial from mongodb docs its not quite clear how to do it.

Im fairly new to mongodb Thanks.

There isn't any such thing as a collection inside another collection with mongo. A collection is a collection of documents.

There are a couple of ways to link documents to other documents, or collections of other data. The correct one to choose is up to you, your data, and your application.

  • Any document can point to another ObjectId from any field
  • You can have an array inside a document
  • Combine the two, and you can have an array of document ids

Mongo is a document store, not a relational database. My suggestion is don't try to use it as a relational database. If what you need is an RDBMS, use one.

Arrays:

http://docs.mongodb.org/manual/reference/operator/query-array/ http://docs.mongodb.org/manual/reference/operator/update-array/

ObjectId:

http://docs.mongodb.org/manual/core/document/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM