简体   繁体   English

这个查询是否可以在nosql中使用(使用mongodb)?

[英]Is this query possible in nosql (with mongodb)?

I use mongoose in my node.js app, and basically have the following models: 我在我的node.js应用程序中使用mongoose,基本上有以下模型:

// Define Car model
CarSchema = new Schema({
  brand  : String,
  type: String,    
  maxSpeed : Number
});
mongoose.model('Car', CarSchema);
// Define User model
UserSchema = new Schema({
  lastname        : String,
  firstname : String,
  cars   : [CarSchema]
});
mongoose.model('User', UserSchema);

I'm really new to NoSQL and I really want to give it a try but I first need to study if this really fits my needs. 我是NoSQL的新手,我真的想尝试一下,但我首先需要研究这是否真的符合我的需求。

With the above models, will I be able to create a query listing all the Users who have a particular type of car among their personal cars ? 使用上述模型,我是否可以创建一个查询,列出所有在其私人汽车中拥有特定类型汽车的用户?

I don't how to do it in mongoose. 我不知道如何在猫鼬中做到这一点。 But in mongodb it possible. 但在mongodb中它是可能的。 So, in mongodb shell query will looks like this: 所以,在mongodb shell中查询将如下所示:

db.users.find({"cars.type":"sport"})

Above query return all users thats have car with type 'sport' in their nested collection of cars. 以上查询返回所有在其嵌套汽车集合中具有“sport”类型的汽车的用户。

Mongodb dot notation documentation. Mongodb 点符号文档。

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

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