mongodb、特に node.js の mongoose パッケージに問題があります。私は次のスキーマを持っています:
var Schema = mongoose.Schema;
var location = new Schema ({
nomville: {type: String, required: true},
description: {type: String, required: true},
quartier: [quartier],
critere: [misc],
modified: {type: Date, default: Date.now}
});
var misc = new Schema ({
publictransp: {type: Number},
culture: {type: Number},
traffic: {type: Number},
nature: {type: Number},
supermarket: {type: Number},
school: {type: Number},
sport: {type: Number},
nightlife: {type: Number},
mean: {type: Number}
});
var rue = new Schema ({
nomrue: {type: String},
modified: {type: Date, default: Date.now}
});
var quartier = new Schema ({
nomquartier: {type: String},
listerue: [rue],
modified: {type: Date, default: Date.now}
})
var ObjModel = mongoose.model('Obj',location);
そして、Jqueryクエリを使用してこのスキーマのオブジェクトを投稿しようとすると、次のようになります:
[エラー: キー $conditionalHandlers は '$' で開始してはなりません]
何か案が ?私はこれで完全に立ち往生しています。
EDIT1:これが投稿機能です:
//CREATE PRODUCTS
app.post('/api/products', function(req,res){
var product;
console.log("POST: ");
console.log(req.body);
product = new ObjModel({
nomville: req.body.nomville,
description: req.body.description,
quartier: [quartier],
critere: [misc],
});
product.save(function(err){
if (!err) {
return console.log("created");
} else {
return console.log(err);
}
});
return res.send(product);
});
EDIT2:ここにクエリがあります
jQuery.post("/api/products", {
"nomville": "Strasbourg",
"description": "Ville de Strasbourg",
"quartier": [
{
"nomquartier": "Centre",
"listerue": [
{
"nomrue": "22 Novembre"
},
{
"nomrue": "Abattoir"
},
{
"nomrue": "Fonderie"
},
{
"nomrue": "Francs Bourgeois"
}
]
},
{
"nomquartier": "Cité de l'Ill",
"listerue": [
{
"nomrue": "Anguille (chemin de l)"
},
{
"nomrue": "Civelles (promenade des)"
},
{
"nomrue": "Hechner (rue)"
},
{
"nomrue": "Phario (pont)"
}
]
},
{
"nomquartier": "Krutenau",
"listerue": [
{
"nomrue": "Abreuvoir (rue de l)"
},
{
"nomrue": "Bain Finkwiller (rue du)"
},
{
"nomrue": "Fustel de Coulanges (quai)"
},
{
"nomrue": "Hôpital (place de l)"
}
]
}
],
"critere":[
{
"publictransp": 2,
"culture": 8,
"traffic": 5,
"nature": 7,
"supermarket": 3,
"school": 5,
"sport": 6,
"nightlife": 4,
"mean": 5
},
]
}, function(data, textStatus, jqXHR) {
console.log("Post resposne:"); console.dir(data); console.log(textStatus); console.dir(jqXHR);
});
それは、クエリを投稿した後に得られるものです。
[
{
"nomville": "Strasbourg",
"description": "Ville de Strasbourg",
"_id": "526ecdd3a78290010c000004",
"__v": 0,
"modified": "2013-10-28T20:49:23.235Z",
"critere": [],
"quartiers": [
{
"_id": "526ecdd3a78290010c000005",
"listerue": []
}
]
}
]
これは正常ですか??