जो मैं करने की कोशिश कर रहा हूं वह एक ब्लॉग पोस्ट के लिए एक नया {फ़ील्ड: वैल्यू} जोड़ना है। तो उदाहरण के लिए, यदि मैं वेबसाइटों पर इंप्रेशन ट्रैकिंग शुरू करना चाहता हूं। Blog_posts.url: 'http://www.example.com/01.html' मैं उस ब्लॉग पोस्ट के लिए इंप्रेशन विशेषता कैसे जोड़ सकता हूं?MongoDB, मौजूदा एम्बेडेड दस्तावेज़ में एकाधिक स्तर फ़ील्ड नोटेशन के साथ नया {फ़ील्ड: वैल्यू} जोड़ें?
मेरे वर्तमान दस्तावेज़ संरचना:
{
email_address: '[email protected]mple.com',
password: 'random_password',
first_name: 'John',
last_name: 'Doe',
user_type: 'WEBMASTER',
newsletter: 'NO',
websites: [{
main_title: 'My Blog Website',
main_url: 'http://www.example.com',
blog_posts: [{
url: 'http://www.example.com/01.html',
title:'My first blog post',
description: 'My first description.'
}, {
url: 'http://www.example.com/02.html',
title: 'My second blog post',
description: 'My second description.'
}, {
url: 'http://www.example.com/03.html',
title: 'My third blog post',
description: 'My third description.'
}, {
url: 'http://www.example.com/04.html',
title: 'My fourth blog post',
description: 'My fourth description.'
}]
}]
}
यहाँ है कि मैं क्या अद्यतन का उपयोग करते हुए और Upsert सही बनाने काम करेगा सोचा है।
db.my_collection.update ({ 'websites.blog_posts.url': 'http://www.example.com/01.html'} { '$ सेट': { 'websites.blog_posts। छापे ': 549}}, सच)
त्रुटि है कि मैं प्राप्त है: * का उपयोग कर स्ट्रिंग फ़ील्ड नाम [blog_posts] *
शायद "$ सेट" है सरणी को संलग्न नहीं कर सकते इसके लिए सही नहीं है या शायद मैं डॉट नोटेशन के साथ उस गहरे संदर्भ नहीं दे सकता? मैंने कल मोंगोडीबी का उपयोग करना शुरू किया, कोई भी मदद महान होगी।
धन्यवाद!
आप सही हैं, मेरी समस्या एक स्कीमा और एक एम्बेडेड दस्तावेज़ संग्रहीत करने के लिए मेरे गलत ब्रैकेट थे। इसके बजाय मैं एक सरणी के लिए ब्रैकेट का उपयोग कर रहा था। मैंने अब उचित स्कीमा के साथ डॉट नोटेशन का उपयोग करके गहरे 4 स्तरों को गहराई से जोड़ा है। – Chris
बहुत बढ़िया, शुभकामनाएँ;) –