我有这个示玛:
S_logs = new mongoose.Schema({
user_ip : {type: mongoose.Schema.Types.ObjectId},
user_id : String,
user_agent : String,
canal_id : String,
theme_id : String,
video_id : String,
osef : String,
time : Number,
action: String,
is_newuser : String,
operator : String,
template : String,
catalogue : String,
referer : String,
from : String,
osef1 : String
});
我这样填写:
while (i < logs.length) {
DB_logs[i] = new Model({
user_ip : logs[i].user_ip,
user_id : logs[i].user_id,
user_agent : logs[i].user_agent,
canal_id : logs[i].canal_id,
theme_id : logs[i].theme_id,
video_id : logs[i].video_id,
osef : logs[i].osef,
time : logs[i].time,
action: logs[i].action,
is_newuser : logs[i].is_newuser,
operator : logs[i].operator,
template : logs[i].template,
catalogue : logs[i].catalogue,
referer : logs[i].referer,
from : logs[i].from,
osef1 : logs[i].osef1
});
i = i + 1;
}
没有 _id 字段,我不明白它有什么用,但是 mongoose 似乎希望将 user_ip 转换为 ObjectId,但我不希望,user_ip 是一个数据字段,而不是索引!
我怎样才能:
-Tell mongoose that I do not want a _id
-Auto generate a id for each object?
我做错了什么,导致 mongoose 将数据字段作为 id?
{ message: 'Cast to ObjectId failed for value "157.55.39.208" at path "user_ip"',
name: 'CastError',
type: 'ObjectId',
value: '157.55.39.208',
path: 'user_ip' }
最佳答案
这看起来像是一个简单的拼写错误:
user_ip : {type: mongoose.Schema.Types.ObjectId},
user_id : String,
应该是
user_id : {type: mongoose.Schema.Types.ObjectId},
user_ip : String,
关于javascript - 为什么 Mongoose 想要将我的字符串转换为 ObjectId?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24913570/