0
Im使用以下架構和代碼在Mongo中創建集合以及Indexer並插入數據。請注意,該集合是根據categoryName動態創建的。Mongo Indexing - Nodejs
var employeeSchema = new mongoose.Schema({
categoryId : {type: String, required: true },
loc : {type: {lon: Number, lat: Number}, index: '2d'},
// createdBy : {type: String, required: true },
createDate : {type: Date, default: Date.now}
});
exports.register = function (objEmployee , callback)
{
var emp = db.model(objEmployee.categoryName, employeeSchema);
var objSchema = new emp(objEmployee);
objSchema.save(function (err) {
if (err) return callback(err);
console.info ('Data inserted successfully.');
return callback(null);
});
};
林能夠插入數據,但是當我運行基礎上,radious查詢,當我運行我碰到下面的錯誤。
Sat Sep 29 20:21:24 uncaught exception: error: {
"$err" : "can't find special index: 2d for: { loc: { $within: { $center: [ [ 50.9393925139, -114.0 ], 2.0 ] } } }",
"code" : 13038
在我的代碼中發生了什麼問題?
什麼代碼拋出的錯誤? – JohnnyHK