相关疑难解决方法(0)

在Mongoose Schema中使用多个值的唯一文档

我有一个特殊情况,我们的集合需要根据电子邮件地址和sweepstakes_id的组合确保每个文档都是唯一的.我看了一遍,但我找不到如何完成这种类型的验证.

架构定义:

var submissionSchema = new Schema({
    client_id: {
        type: Schema.Types.ObjectId,
        ref: 'Client',
        index: true
    },
    sweepstakes_id: {
        type: Schema.Types.ObjectId,
        ref: 'Sweepstakes',
        index: true
    },
    email: {
        type: String,
        index: true
   },
   data: {
        type: Schema.Types.Mixed,
        default: []
   }
});
Run Code Online (Sandbox Code Playgroud)

mongoose mongodb node.js

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

多列唯一mongoose nodejs组合

客观的

为两列创建唯一性

我试过的

这是我的架构,

var mongoose = require('mongoose');

// location table Schema

var locationSchema = new mongoose.Schema({

    locationId: { type: String, required: true },
    stockingLocationId: { type: String, required: true},
    parentStockingLocationId: { type: String },
    stockingLocationDescription: { type: String },
    created: { type: Date, default: Date.now  },
    lastModified: { type: Date, default: Date.now },
    isActive: { type: Boolean , default : true },
    isDeleted: { type: Boolean , default : false }

});
Run Code Online (Sandbox Code Playgroud)

两列是locationIdstockingLocationId

我试过 locationSchema.index({locationId:1, …

mongoose mongodb node.js

2
推荐指数
3
解决办法
6908
查看次数

Mongoose:schema.index 多行

我正在研究一个使用 mongoose 填充 MongoDB 的示例。

var eventSchema = new mongoose.Schema({
    _id: { type: String },
    name: { type: String, required: true},
    description: {type: String},
    venue: {type: String},   });   
eventSchema.plugin(require('./plugins/pagedFind'));
eventSchema.index({ name: 1 });
eventSchema.index({ date: 1 });
eventSchema.index({ venue: 1 });
Run Code Online (Sandbox Code Playgroud)

我不知道 schema.index 是什么;所以我查了一下;http://mongoosejs.com/docs/guide.html;我了解到,除了默认的 _id 排序之外,这是一种对集合进行排序的方法。

但是我写的和下面的有什么区别吗?

eventSchema.index({ name: 1, date: 1,venue: 1  });
Run Code Online (Sandbox Code Playgroud)

mongoose mongodb node.js

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

标签 统计

mongodb ×3

mongoose ×3

node.js ×3