简体   繁体   English

如何选择 mongoose 的系列?

[英]How do i choose collection with mongoose?

How do i select which collection i want to access with mongoose?我如何 select 我想用 mongoose 访问哪个集合? I have only used the normal mongo db before.我以前只使用过普通的 mongo db。 Before i just did mongo.collection.something()在我刚刚做 mongo.collection.something()

But on mongoose that don't work.但是在 mongoose 上不起作用。 I have tried to look at theirs docs but it not clear how to choose the collection, i have also tried to do mongoose.collection, but that don't work either.我试图查看他们的文档,但不清楚如何选择集合,我也尝试过 mongoose.collection,但这也不起作用。 It should be simply to just choose what collection you want to use.应该只是选择您要使用的集合。

Anyone that can tell me how i access the collection of the database?谁能告诉我如何访问数据库的集合?

You need to mention schema before you perform any operation on collection using mongoose.在使用 mongoose 对集合执行任何操作之前,您需要提及架构。 Create schema as below:创建模式如下:

// define a schema
var animalSchema = new Schema({ name: String, type: String });
var Animal = mongoose.model('Animal', animalSchema);

After this you can perform query operations as mentioned here: https://mongoosejs.com/docs/guide.html#query-helpers https://mongoosejs.com/docs/queries.html在此之后,您可以执行此处提到的查询操作: https://mongoosejs.com/docs/guide.html#query-helpers https://mongoosejs.com/docs/queries.ZFC35FDC70D5FC69D263EZ888A3

To save or update follow save method from above mentioned document.要保存或更新上述文档中的保存方法。

Make sure you follow same version as current mongoose version is 5.7.2确保您遵循与当前 mongoose 版本相同的版本是 5.7.2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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