Ich habe 2 Sammlungen für das Produkt und Produkt price.In Produktsammlung gibt es ein product_id Feld mit dem Namen, der in String und demselben Feld ist in Product Sammlung mit demselben Namen wie String.How kann ich Schema dafür entscheiden, und wie bevölkern verwenden für welches Produkt ein Feld als Produktpreis dabei ist. Produktfelder sind = _id, Product_id, name; Produktpreisfelder sind = _id, Produkt_id, Preis; Derselbe Wert ist in Product_id für beide Sammlungen vorhanden. const productpriceSchema = mongoose.Schema({ Product_id: { type: mongoose.Schema.ObjectID, ref: 'Product' }, price: String });
Wie befüllen Abfrage in Nodejs und Mongodb?
const productSchema = mongoose.Schema({ Product_Name: type: String, User_Object_ID :type: String, cid :type: String });
const Product = module.exports = mongoose.model('Product', productSchema);
const Productprice = module.exports = mongoose.model('Product_price', productpriceSchema);
module.exports.productwithprice = function(callback,limit){ Productprice.find({}, callback).populate('Product_id') }
Diese Abfrage funktioniert nicht. In meinem Produkt Kollektion ist die _id in Form von „_id“: ObjectId („595f4cb77e713872c1297941“), die ich mit Product Sammlung Product_id übereinstimmen soll: „595f4cb77e713872c1297941“. Bitte hilf mir dabei. –
Können Sie Ihren Code bitte posten? – sohamdodia
Ich habe meinen obigen Code eingereicht. –