Mongoose TypeError:不能使用"in"运算符在其中搜索"_id" [英] Mongoose TypeError: Cannot use 'in' operator to search for '_id' in
问题描述
我有一个Rails开发人员尝试使用骨干,并使用Backbone.js应用程序书-我的第一个Backbone/Node/Mongo应用程序,请保持柔和.
I've a rails developer trying my hand at backbone and using the Backbone.js application book - my first Backbone / Node / Mongo app so be gentle.
我已经回答了类似的问题,并且已经被困了12个小时,所以我认为是时候丢下毛巾了.错误在上方和下方
I've poured over the similar questions and have been stuck for 12 hours now so I think it's time to throw in the towel. error is above and below
[TypeError: Cannot use 'in' operator to search for '_id' in YES PLEASE]
我正在尝试将Book保存到图书馆,这是我的模式.
I'm trying to save a Book to the library, here is my schema.
var Keywords = new mongoose.Schema({
keyword: String
});
var Book = new mongoose.Schema({
title: String,
author: String,
releaseDate: Date,
keywords: [ Keywords ]
});
当我做一个简单的Ajax帖子时,将显示并保存关键字,但是当我尝试从视图中添加它们时,它们将失败.这是library.js视图.
When I do a simple Ajax post, the Keywords get displayed and saved, but when I try to add them from the view, they fail. Here is the library.js view.
var app = app || {};
app.LibraryView = Backbone.View.extend({
el: "#books",
events: {
'click #add': "addBook"
},
initialize: function() {
this.collection = new app.Library();
this.collection.fetch({reset: true});
this.render();
this.listenTo(this.collection, 'add', this.renderBook );
this.listenTo(this.collection, 'reset', this.render)
},
render: function() {
this.collection.each(function(item) {
this.renderBook(item);
}, this);
},
renderBook: function(item) {
var bookView = new app.BookView({
model: item
});
this.$el.append(bookView.render().el );
},
addBook: function(e) {
e.preventDefault();
var formData = {};
$('#addBook div').children('input').each(function( i,el ) {
if( $( el ).val() != '' )
{
if( el.id ==="kewords" ) {
_.each( $(el).val().split(' '), function( keyword ){
formData[ el.id ].push({ 'keyword': keyword });
});
} else if ( el.id ==='releaseDate' ){
formData[ el.id ] = $("#releaseDate").datepicker('getDate').getTime();
} else {
formData[ el.id ] = $( el ).val();
}
}
$( el ).val('')
});
this.collection.create( formData );
}
});
任何帮助都是最欢迎的.另外,调试JavaScript的最佳做法是什么?进入控制台并向下钻取?是否有更好的调试器库可用于节点?
Any help would be most welcome. Also, what are best practices for debugging javascript? Going into the console and drilling down? Is there a better debugger library to use with node?
谢谢
推荐答案
我猜您的发布数据JSON对象属性错误.更正后,我遇到了同样的问题,问题消失了.
I guess your post data JSON objects properties is wrong. I faced same problem after my correction, the issue is gone.
问题状态:
{"userId": "58821f9b1b059b515a53d44b","dashboard":"mobile_dashboard"}
更正后:
{"userId": "58821f9b1b059b515a53d44b","dashboard":{"title":"mobile_dashboard","viewData":{"className":"BuilderDroppableZone"}}}
这篇关于Mongoose TypeError:不能使用"in"运算符在其中搜索"_id"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!