我想显示'会议'收集会议,其主机电子邮件(来自'用户'集合)包含短语'agu'。这里会议主持人的电子邮件是从用户集合中调用的:
var host = meetings.host
db.collection('users').findOne({'_id': new ObjectId(host)}, function(err, doc) {
var emails = [];
if (doc.emails) {
doc.emails.forEach(function(e) {
emails.push(e.email + (e.primary ? '(P)' : ''));
});
}
var email = emails.join(', ');
以下是使用包含短语“fall”的DisplayValue(title)的meetings集合属性进行代码查找的示例:
function findMeetings(db, callback) {
var cursor = db.collection('meetings').find({
'name.displayValue': {'$regex': 'fall', '$options': 'i' }
});
cursor.count(function(err, count) {
console.log('count: ' + count);
var cnt = 0;
cursor.each(function(err, doc) {
assert.equal(err, null);
if (doc != null) {
findNumberOfNotesByMeeting(db, doc, function() {
cnt++;
if (cnt >= count) { callback(); }
});
}
});
});
}
这是meetings.attendees属性的样子:
attendees: [{
email: {type: String, default: ''},
userId: {type: String, default: ''},
isPresenter: {type: Boolean, default: false},
invitationStatus: {type: String, default: ''},
invitationResent: {type: Boolean, default: false}
}],
以下是用户架构的外观:
var userSchema = mongoose.Schema({
createdOn: { type: Number, default: 0},
updatedOn: { type: Number, default: 0},
emails: [{
email: { type: String, default: ''},
confirmed: { type: Boolean, default: false},
primary: { type: Boolean, default: false}
}],
authentication: [{
token: { type: String, default: ''},
createdOn: { type: Number, default: 0}
}],
password: {
salt: { type: String, default: ''},
hash: { type: String, default: ''}
},
consecutiveFailedLoginAttempts: { type: Number, default: 0},
communicationOptions: {
customerContact: { type: Boolean, default: false}
},
profileCompleted: { type: Boolean, default: false},
profile: {
firstName: {
searchValue: { type: String, default: ''},
displayValue: { type: String, default: ''}
},
lastName: {
searchValue: { type: String, default: ''},
displayValue: { type: String, default: ''}
},
nickname: { type: String, default: ''},
companyName: { type: String, default: ''},
title: { type: String, default: ''},
location: { type: String, default: ''},
imageURL: { type: String, default: ''}
},
forgotPassword: {
token: {type: String, default: ''},
forgotOn: {type: Number, default: 0}
},
deleteAccount: {
token: {type: String, default: ''},
actionOn: {type: Number, default: 0},
confirmedOn: {type: Number, default: 0}
},
anonymous: {type: Boolean, default: false}
});