I have this shema:
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
});
That I fill like this:
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;
}
There is no _id field, and I don t understand what use it have, but mongoose seems to want user_ip to be casted to ObjectId, that I do not want, user_ip is a data field, not a index!
How can I either:
-Tell mongoose that I do not want a _id
-Auto generate a id for each object?
And what did I do wrong so that mongoose took a data field for a 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' }
This looks like a simple typo:
user_ip : {type: mongoose.Schema.Types.ObjectId},
user_id : String,
should be
user_id : {type: mongoose.Schema.Types.ObjectId},
user_ip : String,
take user_ip as String
user_ip :String