如何在mongoose中找到具有属性值的对象路径?

时间:2015-08-26 18:44:26

标签: node.js mongodb mongoose

我想使用一个名为' task'的对象。在我的mongodb数据库中。任务可以将一个或多个任务作为其子项。我需要找到一个可能位于层次结构任何级别的任务,其中包含_id或其他属性值。我怎么能用猫鼬或mongodb做到这一点? 我的任务架构如下:

    var mongoose = require('mongoose');

    var Project = require(./project.js); 
    var Resource = require(./resource.js); 
    var Group = require(./group.js); 
    var Phase = require(./phase.js); 
    var Objective = require(./objective.js); 
    var Milestone = require(./milestone.js); 
    var Decision_tag = require(./decision_tag.js); 

    var createInfo = require(./plugins/createInfo); 


    var taskSchema = new mongoose.Schema(
      {
        title :{ type : String, unique : true, required : true,  trim :true},
        resources :[{type : mongoose.Schema.Types.ObjectId , ref : 'Resource', required, false}], 
        groups :[{type : mongoose.Schema.Types.ObjectId , ref : 'Group', required, false}], 
        tasks :[{type : mongoose.Schema.Types.ObjectId , ref : 'Task', required, false}], 
        decision_tags :[{type : mongoose.Schema.Types.ObjectId , ref : 'Decision_tag' , required : false}]

      });
    taskSchema.plugin(createInfo);


    module.exports = mongoose.model('Task' , 'taskSchema' , tasks);

0 个答案:

没有答案