I wanted to create a schema , with multiple object id with each object id containing a Number.
Like for this data,
[ "user": [["collection1",1], ["collection2", 3], ["collection4": 4]
where user is a user object id, and collection1, collection2 .... are collection object id, and other are just number.
const derivedSchema = new mongoose.Schema(
{
user: {type: ObjectId, ref: "User"},
collections: {type: [ObjectId], ref="collection"}],
);
I tried to change like put [ObjectId, Number] if it would look like my data
and tried to save as like this
let collected = new derivedSchema({
"user": uid,
"collections": [cid, 12],
})
collected.save()
where cid is collectionid, uid is userid , 12 number, i passed through in for loop.
But it is not working. Is there any way to solve this ? Thank you
At end result i should show like
[
"user1": { ["col1",1], ["col2", 5]},
"user2": { ["col1",55], ["col2", 35]},
]
Any idea would be really helpful?
var mongoose = require('mongoose');
var Schema=mongoose.Schema;
const derivedSchema = new mongoose.Schema(
{
user: {
type: Schema.Types.ObjectId,
ref: "User"
},
collections:{
type:[Schema.Types.ObjectId],
ref:"collection"
}
);