Dynamically create collection with Mongoose

前端 未结 6 1505
我寻月下人不归
我寻月下人不归 2020-12-17 08:55

I want to give users the ability to create collections in my Node app. I have really only seen example of hard coding in collections with mongoose. Anyone know if its poss

6条回答
  •  春和景丽
    2020-12-17 09:46

    From mongo docs here: data modeling

    In certain situations, you might choose to store information in several collections rather than in a single collection.

    Consider a sample collection logs that stores log documents for various environment and applications. The logs collection contains documents of the following form:

    { log: "dev", ts: ..., info: ... } { log: "debug", ts: ..., info: ...}

    If the total number of documents is low you may group documents into collection by type. For logs, consider maintaining distinct log collections, such as logs.dev and logs.debug. The logs.dev collection would contain only the documents related to the dev environment.

    Generally, having large number of collections has no significant performance penalty and results in very good performance. Distinct collections are very important for high-throughput batch processing.

提交回复
热议问题