I´ve defined the following schema with Mongoose:
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var ObjectId = Schema.Types.ObjectId;
var New = new Schema({
_id: ObjectId,
lang: String,
formatted: Boolean,
downloaded: Date,
content: {
title: String,
link: String,
description: String,
meta: String,
author: String
}
});
module.exports = New;
And I´m trying to execute the following query:
NewsModel.find({'lang':'en', 'content.link':'test'}).exec(callback);
The query doesn' t respond and it never enters into the callback function. It' s strange, because this type of query (search into two String fields) works good with another Schema that I' ve defined, but no with this one. The other Schema is more is simpler, without any embedded document.
The strange thing is that the following works:
NewsModel.find({'lang':'en', 'formatted':true}).exec(callback);
Is there any Schema error? Any idea what I' m doing wrong?
Thank you very much,
Luis Cappa.
[UPDATED]
I tried your suggestions, but no way. I think that there are only two options:
1. The Schema that I posted has something wrong.
2. Mongoose has problems querying to documents that embed complex parameters such as another document.
I've worked with MongoDB shell, MongoDB Java Driver and Spring MongoDB Data and that' s the first time that I experience this strange behavior.
The queries that I' ve tested are:
NewsModel.find({'lang':'en', 'content.link':'test'}).exec(callback);
NewsModel.find({'lang':'en'}).where('content.link').equals('test').exec(callback);
NewsModel.find({'content.link':'test'}).where('lang').equals('en').exec(callback);
NewsModel.find({'content.link':'test'}).exec(callback); // That demonstrates that Mongoose has problems with subelements.
NewsModel.find().where('content.link').equals('test').exec(callback); // This one too.
And one example that works perfectly with MongoDB shell:
db.news.find({ 'content.link': /test/, lang: 'en' })
I' m worried that Mongoose do not returns an empty response with zero results. Instead, it maintains the application in stand by waiting and waiting for a response and never enters at the callback function.
Any ideas? Did you experienced something similar?
Thanks a lot!