我面临一个奇怪的问题,所以我使用MongoDB为Meteor app插入记录。
Books.insert(query);
这里查询是从查询构建器函数返回的字符串。问题是当我运行查询时,会插入记录但是将查询切成单个字符。 所以
var query = "{hasFinished:false,currentPage:0,name:"Christmas Carol",author:"Charles Dickens",img:"Christmas Carol",numOfPages:"123",dateStarted:"27-02-2015",dateToFinish:"06-03-2015"}"
id = Books.insert(query);
保存的记录是
{ "0" : "{", "1" : "h", "2" : "a", "3" : "s", "4" : "F", "5" : "i", "6" : "n", "7" : "i", "8" : "s", "9" : "h", "10" : "e", "11" : "d", "12" : ":", "13" : "f", "14" : "a", "15" : "l", "16" : "s", "17" : "e", "18" : ",", "19" : "c", "20" : "u", "21" : "r", "22" : "r", "23" : "e", "24" : "n", "25" : "t", "26" : "P", "27" : "a", "28" : "g", "29" : "e", "30" : ":", "31" : "0", "32" : ",", "33" : "n", "34" : "a", "35" : "m", "36" : "e", "37" : ":", "38" : "\"", "39" : "C", "40" : "h", "41" : "r", "42" : "i", "43" : "s", "44" : "\"", "45" : ",", "46" : "a", "47" : "u", "48" : "t", "49" : "h", "50" : "o", "51" : "r", "52" : ":", "53" : "\"", "54" : "C", "55" : "h", "56" : "a", "57" : "r", "58" : "l", "59" : "e", "60" : "s", "61" : "\"", "62" : ",", "63" : "i", "64" : "m", "65" : "g", "66" : ":", "67" : "\"", "68" : "C", "69" : "h", "70" : "r", "71" : "i", "72" : "s", "73" : "\"", "74" : ",", "75" : "n", "76" : "u", "77" : "m", "78" : "O", "79" : "f", "80" : "P", "81" : "a", "82" : "g", "83" : "e", "84" : "s", "85" : ":", "86" : "\"", "87" : "1", "88" : "2", "89" : "3", "90" : "\"", "91" : ",", "92" : "d", "93" : "a", "94" : "t", "95" : "e", "96" : "S", "97" : "t", "98" : "a", "99" : "r", "100" : "t", "101" : "e", "102" : "d", "103" : ":", "104" : "\"", "105" : "2", "106" : "7", "107" : "-", "108" : "0", "109" : "2", "110" : "-", "111" : "2", "112" : "0", "113" : "1", "114" : "5", "115" : "\"", "116" : ",", "117" : "d", "118" : "a", "119" : "t", "120" : "e", "121" : "T", "122" : "o", "123" : "F", "124" : "i", "125" : "n", "126" : "i", "127" : "s", "128" : "h", "129" : ":", "130" : "\"", "131" : "0", "132" : "6", "133" : "-", "134" : "0", "135" : "3", "136" : "-", "137" : "2", "138" : "0", "139" : "1", "140" : "5", "141" : "\"", "142" : "}", "_id" : "cvinMJJP3PweJN9Zj" }
但是当我在浏览器控制台中运行查询时
Books.insert({hasFinished:false,currentPage:0,name:"Christmas Carol",author:"Charles Dickens",img:"Christmas Carol",numOfPages:"123",dateStarted:"27-02-2015",dateToFinish:"06-03-2015"});
它完美地运作。任何帮助将不胜感激。
感谢
答案 0 :(得分:1)
您的查询应该是对象,而不是字符串。
尝试:
var query = {hasFinished:false,currentPage:0,name:"Christmas Carol",author:"Charles Dickens",img:"Christmas Carol",numOfPages:"123",dateStarted:"27-02-2015",dateToFinish:"06-03-2015"};
id = Books.insert(query);