标签: subdocument

使用mongoDB插入子文档

我在集合中有以下文档:

"_id" : "2",
"workspace" : [{
        "name" : "1",
        "widgets" : [ ]
    },{
        "name" : "2",
        "widgets" : [ ]
    },{
        "name" : "3",
        "widgets" : [ ]
    },{
        "name" : "4",
        "widgets" : [ ]
    }
]}
Run Code Online (Sandbox Code Playgroud)

如何{id: "1", blabla: "blabla"}在"小部件"中插入"名称"3?

javascript mongodb meteor subdocument

5
推荐指数
1
解决办法
1万
查看次数

Mongoose用于子文档中的var in循环

我创建了这个架构mongoose Schema:

socialAccount =  new Schema({
    socialNetwork : { type : String , required : true},
    userid : { type : Number,  required :  true },
    username : String
},{_id : false});
person = new Schema({
    id : { type : Number,  unique : true, required : true , dropDups :  true },
    firstname : String,
    lastname : String,
    socialAccounts : [socialAccount],
    updated : { type : Date, default : Date.now },
    enable : { type : Boolean …
Run Code Online (Sandbox Code Playgroud)

for-loop mongoose mongodb node.js subdocument

5
推荐指数
1
解决办法
4693
查看次数

在mongodb中编辑子文件NN关系

我有一个应用程序,其中一篇文章可以链接到多个平台.

文章包含平台和平台列表,还包含文章列表.

有关更多详细信息,请查看几个月前我问过的stackoverflow问题.

/sf/answers/2826416841/

问题是如何创建文章和实现文章和平台之间的NN关系.

我有创建文章和删除文章设置,以便列表在平台中更新.

如何实现编辑文章,以便更新哪些平台链接到文章?

为了创建和编辑链接平台,我使用下拉菜单,其中可以选择多个选项.必要的代码可以在先前链接的问题中找到.

relationship mongoose mongodb async.js subdocument

5
推荐指数
1
解决办法
235
查看次数

在mongoose中将select:false设置为子文档数组

在mongoose上,有一个很好的选择,默认情况下使用该select: false选项从查询中删除一些字段.

例如:

var FileSchema = new Schema({
  filename: String,
  filesize: Number,
  base64Content: {type: String, select:false}
});

[...]

FileModel.find({}, function(err, docs) {
  // docs will give me an array of files without theirs content
});
Run Code Online (Sandbox Code Playgroud)

现在,我如何在子文档数组的字段中使用相同的选项?

(即在以下示例中,设置select: falsecomments字段)

var PostSchema = new Schema({
  user: ObjectId,
  content: String,
  createdAt: Date,
  comments: [{
    user: ObjectId,
    content: String,
    createdAt: Date
  }]
});

[...]

FileModel.find({}, function(err, docs) {
  // docs will give me an array of files without …
Run Code Online (Sandbox Code Playgroud)

schema mongoose mongodb node.js subdocument

3
推荐指数
1
解决办法
1084
查看次数

是否可以使用mongoDB和Node.js返回多个子文档?

我目前有一个架构,目前看起来像:

var User = new Schema({
    id: String,
    firstName: String,
    lastName: String,
    password: String,
    username: String,
    position: [{
          title: String,
          location: String,
          start: String,
          term:Number,
          description:String,
                    date: {type: Date, default: Date.now}
  }]

});
Run Code Online (Sandbox Code Playgroud)

我有两个用户,每个用户有两个嵌入式位置文档.

用户1:

"position" : [ 
    {
        "title" : "Web Developer",
        "location" : "Dublin",
        "start" : "May 2017",
        "term" : 6,
        "description" : " Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus quis erat vitae dsit amet, consectetur adipiscing elit. Vivamus quis erat vitae dolor tempus euismod …
Run Code Online (Sandbox Code Playgroud)

mongoose mongodb node.js subdocument embedded-documents

1
推荐指数
1
解决办法
388
查看次数

如何删除嵌入在 MongoDB 子数组中的子文档(按 Id)?

ProductCollection: 
{
  _id: { ObjectId('x1')},
  products: [ 
              { listPrice: '1.90', product: {id: 'xxx1'} },
              { listPrice: '3.90', product: {id: 'xxx2'} },
              { listPrice: '5.90', product: {id: 'xxx3'} }
            ]
},
{
  _id: { ObjectId('x2')},
  products: [ 
              { listPrice: '2.90', product: {id: 'xxx4'} },
              { listPrice: '4.90', product: {id: 'xxx5'} },
              { listPrice: '5.90', product: {id: 'xxx6'} }
            ]
},
Run Code Online (Sandbox Code Playgroud)

我想从集合 (x1) 中删除子文档 (xxx3),然后尝试以下操作:

ProductCollection.update(
{ 
  "_id": mongoose.Types.ObjectId('x1')  
}, 
{ 
  $pull : { 'products.product': {id: 'xxx3' } } 
} 
Run Code Online (Sandbox Code Playgroud)

这似乎不起作用。谁能帮帮我吗?谢谢

pull mongodb subdocument

0
推荐指数
1
解决办法
1824
查看次数