<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # MongoDB JavaScript 教程 > 原文: [http://zetcode.com/db/mongodbjavascript/](http://zetcode.com/db/mongodbjavascript/) MongoDB JavaScript 教程展示了如何在 JavaScript 中創建與 MongoDB 一起使用的程序。 本教程使用本地 mongodb 驅動程序。 (還有其他解決方案,例如 Mongoose 或 Monk。) [Tweet](https://twitter.com/share) ## MongoDB MongoDB 是 NoSQL 跨平臺的面向文檔的數據庫。 它是可用的最受歡迎的數據庫之一。 MongoDB 由 MongoDB Inc.開發,并作為免費和開源軟件發布。 MongoDB 中的記錄是一個文檔,它是由字段和值對組成的數據結構。 MongoDB 文檔與 JSON 對象相似。 字段的值可以包括其他文檔,數組和文檔數組。 MongoDB 將文檔存儲在集合中。 集合類似于關系數據庫中的表以及行中的文檔。 ## 安裝 MongoDB 服務器 以下命令可用于在基于 Debian 的 Linux 上安裝 MongoDB。 ```js $ sudo apt-get install mongodb ``` 該命令將安裝 MongoDB 隨附的必要包。 ```js $ sudo service mongodb status mongodb start/running, process 975 ``` 使用`sudo service mongodb status`命令,我們檢查`mongodb`服務器的狀態。 ```js $ sudo service mongodb start mongodb start/running, process 6448 ``` `mongodb`服務器由`sudo service mongodb start`命令啟動。 ## MongoDB 驅動程序安裝 我們設置了項目。 ```js $ node -v v11.5.0 ``` 我們使用 Node.js 版本 11.5.0。 ```js $ npm i mongodb ``` 我們安裝`mongodb`本機 JavaScript 驅動程序。 `npm`是 Node.js 包管理器。 MongoDB Node.js 驅動程序提供基于回調和基于`Promise`的交互。 ## MongoDB 創建數據庫 `mongo`工具是 MongoDB 的交互式 JavaScript Shell 界面,它為系統管理員提供了一個界面,并為開發者提供了一種直接測試數據庫查詢和操作的方法。 ```js $ mongo testdb MongoDB shell version v4.0.7 ... > db testdb > db.cars.insert({name: "Audi", price: 52642}) > db.cars.insert({name: "Mercedes", price: 57127}) > db.cars.insert({name: "Skoda", price: 9000}) > db.cars.insert({name: "Volvo", price: 29000}) > db.cars.insert({name: "Bentley", price: 350000}) > db.cars.insert({name: "Citroen", price: 21000}) > db.cars.insert({name: "Hummer", price: 41400}) > db.cars.insert({name: "Volkswagen", price: 21600}) ``` 我們創建一個`testdb`數據庫,并在`cars`集合中插入八個文檔。 ## MongoDB `Promise` `Promise`是用于延遲和異步計算的對象。 它表示尚未完成的操作,但有望在將來進行。 ```js asyncFunc() .then(value => { /* success */ }) .catch(error => { /* failure */ }) .finally( => { /* cleanup */}; ``` `then()`方法始終返回`Promise`,這使我們能夠鏈接方法調用。 > **注意**:如果沒有傳遞回調,`MongoClient`的連接將返回一個`Promise`。 我們也可以使用`async/await`語法來處理`Promise`。 ## MongoDB JS 驅動程序 在第一個示例中,我們打印 Node.js 驅動程序的版本。 `driver_version.js` ```js const mongo = require('mongodb'); const MongoClient = mongo.MongoClient; const url = 'mongodb://localhost:27017'; MongoClient.connect(url, { useNewUrlParser: true }, (err, client) => { if (err) throw err; console.log(client.topology.clientInfo); client.close(); }); ``` 在該示例中,我們連接到服務器并找到客戶端信息。 ```js const mongo = require('mongodb'); ``` 我們使用`mongodb`模塊。 ```js const client = mongo.MongoClient; ``` `MongoClient`用于連接到 MongoDB 服務器。 ```js const url = 'mongodb://localhost:27017'; ``` 這是數據庫的 URL。 27017 是 MongoDB 服務器監聽的默認端口。 ```js MongoClient.connect(url, { useNewUrlParser: true }, (err, client) => { ``` 使用`connect()`創建到數據庫的連接。 ```js $ node driver_version.js { driver: { name: 'nodejs', version: '3.2.2' }, os: { type: 'Windows_NT', name: 'win32', architecture: 'x64', version: '10.0.17134' }, platform: 'Node.js v11.5.0, LE' } ``` 驅動程序版本為 3.2.2。 ## MongoDB 列出數據庫集合 `listCollections()`方法列出了數據庫中的可用集合。 `list_collections.js` ```js const mongo = require('mongodb'); const MongoClient = mongo.MongoClient; const url = 'mongodb://localhost:27017'; MongoClient.connect(url, { useNewUrlParser: true }, (err, client) => { if (err) throw err; const db = client.db("testdb"); db.listCollections().toArray().then((docs) => { console.log('Available collections:'); docs.forEach((doc, idx, array) => { console.log(doc.name) }); }).catch((err) => { console.log(err); }).finally(() => { client.close(); }); }); ``` 該示例連接到`testdb`數據庫并檢索其所有集合。 ```js db.listCollections().toArray().then((docs) => { console.log('Available collections:'); docs.forEach((doc, idx, array) => { console.log(doc.name) }); ... ``` `listCollection()`方法在`testdb`數據庫中找到所有集合; 它們被打印到控制臺。 > **注意**:我們應該謹慎使用`toArray()`方法,因為它會導致大量的內存使用。 ```js }).catch((err) => { console.log(err); }).finally(() => { client.close(); }); ``` 在`catch`塊中,我們捕獲了任何潛在的異常,并在`finally`塊中關閉了與數據庫的連接。 > **注意**:我們的應用是控制臺程序; 因此,我們在程序結束時關閉連接。 在 Web 應用中,應重新使用連接。 ```js $ node list_collections.js Available collections: continents cars cities ``` 在我們的數據庫中,我們有這三個集合。 ## MongoDB 數據庫統計 `dbstats()`方法獲取數據庫的統計信息。 `dbstats.js` ```js const mongo = require('mongodb'); const MongoClient = mongo.MongoClient; const url = 'mongodb://localhost:27017'; MongoClient.connect(url, { useNewUrlParser: true }, (err, client) => { if (err) throw err; const db = client.db("testdb"); db.stats((err, stats) => { if (err) throw err; console.log(stats); client.close(); }) }); ``` 該示例連接到`testdb`數據庫并顯示其統計信息。 ```js $ node dbstats.js { db: 'testdb', collections: 3, views: 0, objects: 18, avgObjSize: 57.888888888888886, dataSize: 1042, storageSize: 69632, numExtents: 0, indexes: 3, indexSize: 69632, fsUsedSize: 136856346624, fsTotalSize: 254721126400, ok: 1 } ``` 這是一個示例輸出。 ## MongoDB 查找 `find()`函數為查詢創建一個游標,該游標可用于遍歷 MongoDB 的結果。 `find_all.js` ```js const mongo = require('mongodb'); const MongoClient = mongo.MongoClient; const url = 'mongodb://localhost:27017'; MongoClient.connect(url, { useNewUrlParser: true }, (err, client) => { if (err) throw err; const db = client.db("testdb"); db.collection('cars').find({}).toArray().then((docs) => { console.log(docs); }).catch((err) => { console.log(err); }).finally(() => { client.close(); }); }); ``` 在示例中,我們從`cars`集合中檢索所有文檔。 ```js db.collection('cars').find({}).toArray().then((docs) => { ``` 傳遞空查詢將返回所有文檔。 ```js $ node find_all.js [ { _id: 5cfcfc3438f62aaa09b52175, name: 'Audi', price: 52642 }, { _id: 5cfcfc3a38f62aaa09b52176, name: 'Mercedes', price: 57127 }, { _id: 5cfcfc3f38f62aaa09b52177, name: 'Skoda', price: 9000 }, { _id: 5cfcfc4338f62aaa09b52178, name: 'Volvo', price: 29000 }, { _id: 5cfcfc4838f62aaa09b52179, name: 'Bentley', price: 350000 }, { _id: 5cfcfc4b38f62aaa09b5217a, name: 'Citroen', price: 21000 }, { _id: 5cfcfc4f38f62aaa09b5217b, name: 'Hummer', price: 41400 }, { _id: 5cfcfc5438f62aaa09b5217c, name: 'Volkswagen', price: 21600 } ] ``` 這是輸出。 ## MongoDB 計數文檔 `count()`函數返回集合中匹配文檔的數量。 `count_documents.js` ```js const mongo = require('mongodb'); const MongoClient = mongo.MongoClient; const url = 'mongodb://localhost:27017'; MongoClient.connect(url, { useNewUrlParser: true }, (err, client) => { if (err) throw err; const db = client.db("testdb"); db.collection('cars').find({}).count().then((n) => { console.log(`There are ${n} documents`); }).catch((err) => { console.log(err); }).finally(() => { client.close(); }); }); ``` 該示例計算`cars`集合中的文檔數。 ```js $ node count_documents.js There are 8 documents ``` 現在,汽車集合中有八個文檔。 ## MongoDB `findOne` `findOne()`方法返回一個滿足指定查詢條件的文檔。 如果多個文檔滿足查詢條件,則此方法將根據反映磁盤上文檔順序的自然順序返回第一個文檔。 `find_one.js` ```js const MongoClient = require('mongodb').MongoClient; const url = 'mongodb://localhost:27017'; MongoClient.connect(url, { useNewUrlParser: true }, (err, client) => { if (err) throw err; const db = client.db("testdb"); let collection = db.collection('cars'); let query = { name: 'Volkswagen' } collection.findOne(query).then(doc => { console.log(doc); }).catch((err) => { console.log(err); }).finally(() => { client.close(); }); }); ``` 該示例從`cars`集合中讀取一個文檔。 ```js let query = { name: 'Volkswagen' } ``` 該查詢包含汽車的名稱-大眾汽車。 ```js collection.findOne(query).then(doc => { ``` 該查詢將傳遞給`findOne()`方法。 ```js $ node find_one.js { _id: 8, name: 'Volkswagen', price: 21600 } ``` 這是示例的輸出。 ## MongoDB 異步/等待示例 使用`async/await`,我們可以輕松地以同步方式處理`Promise`。 `async_await.js` ```js const MongoClient = require('mongodb').MongoClient; const url = 'mongodb://localhost:27017'; async function findCar() { const client = await MongoClient.connect(url, { useNewUrlParser: true }) .catch(err => { console.log(err); }); if (!client) { return; } try { const db = client.db("testdb"); let collection = db.collection('cars'); let query = { name: 'Volkswagen' } let res = await collection.findOne(query); console.log(res); } catch (err) { console.log(err); } finally { client.close(); } } findCar(); ``` 該示例使用`async/await`讀取一個文檔。 ```js async function findCar() { ``` 該函數具有`async`關鍵字。 ```js let res = await collection.findOne(query); ``` 使用`await`,我們等待`findOne()`函數的結果。 ## MongoDB 查詢運算符 可以使用 MongoDB 查詢運算符(例如`$gt`,`$lt`或`$ne`)過濾數據。 `read_gt.js` ```js const mongo = require('mongodb'); const MongoClient = mongo.MongoClient; const url = 'mongodb://localhost:27017'; MongoClient.connect(url, { useNewUrlParser: true }, (err, client) => { if (err) throw err; const db = client.db("testdb"); let query = { price: { $gt: 30000 } }; db.collection('cars').find(query).toArray().then((docs) => { console.log(docs); }).catch((err) => { console.log(err); }).finally(() => { client.close(); }); }); ``` 該示例打印汽車價格大于 30,000 的所有文檔。 ```js let query = { price: { $gts: 30000 } }; ``` `$gt`運算符用于獲取價格大于 30,000 的汽車。 ```js $ node read_gt.js [ { _id: 5d03e40536943362cffc84a7, name: 'Audi', price: 52642 }, { _id: 5d03e40a36943362cffc84a8, name: 'Mercedes', price: 57127 }, { _id: 5d03e41936943362cffc84ab, name: 'Bentley', price: 350000 }, { _id: 5d03e42236943362cffc84ad, name: 'Hummer', price: 41400 } ] ``` 這是示例的輸出。 僅包括價格超過 30,000 的汽車。 `$and`邏輯運算符可用于組合多個表達式。 `read_gt_lt.js` ```js const mongo = require('mongodb'); const MongoClient = mongo.MongoClient; const url = 'mongodb://localhost:27017'; MongoClient.connect(url, { useNewUrlParser: true }, (err, client) => { if (err) throw err; const db = client.db("testdb"); let query = { $and: [{ price: { $gt: 20000 } }, { price: { $lt: 50000 } }] }; db.collection('cars').find(query).toArray().then((docs) => { console.log(docs); }).catch((err) => { console.log(err); }).finally(() => { client.close(); }); }); ``` 在示例中,我們檢索價格在 20,000 到 50,000 之間的汽車。 ```js let query = { $and: [{ price: { $gt: 20000 } }, { price: { $lt: 50000 } }] }; ``` `$and`運算符將`$gt`和`$lt`組合在一起以獲得結果。 ```js $ node read_gt_lt.js [ { _id: 5d03e41336943362cffc84aa, name: 'Volvo', price: 29000 }, { _id: 5d03e41e36943362cffc84ac, name: 'Citroen', price: 21000 }, { _id: 5d03e42236943362cffc84ad, name: 'Hummer', price: 41400 }, { _id: 5d03e42636943362cffc84ae, name: 'Volkswagen', price: 21600 } ] ``` 這是示例的輸出。 ## MongoDB 預測 投影確定從數據庫傳遞哪些字段。 `projections.js` ```js const mongo = require('mongodb'); const MongoClient = mongo.MongoClient; const url = 'mongodb://localhost:27017'; MongoClient.connect(url, { useNewUrlParser: true }, (err, client) => { if (err) throw err; const db = client.db("testdb"); db.collection('cars').find({}).project({_id: 0}).toArray().then((docs) => { console.log(docs); }).catch((err) => { console.log(err); }).finally(() => { client.close(); }); }); ``` 該示例從輸出中排除`_id`字段。 ```js db.collection('cars').find({}).project({_id: 0}).toArray().then((docs) => { ``` `project()`方法設置查詢的投影; 它不包括`_id`字段。 ```js $ node projections.js [ { name: 'Audi', price: 52642 }, { name: 'Mercedes', price: 57127 }, { name: 'Skoda', price: 9000 }, { name: 'Volvo', price: 29000 }, { name: 'Bentley', price: 350000 }, { name: 'Citroen', price: 21000 }, { name: 'Hummer', price: 41400 }, { name: 'Volkswagen', price: 21600 } ] ``` 這是示例的輸出。 ## MongoDB 限制數據輸出 `limit()`方法指定要返回的文檔數,`skip()`方法指定要跳過的文檔數。 `skip_limit.js` ```js const mongo = require('mongodb'); const MongoClient = mongo.MongoClient; const url = 'mongodb://localhost:27017'; MongoClient.connect(url, { useNewUrlParser: true }, (err, client) => { if (err) throw err; const db = client.db("testdb"); db.collection('cars').find({}).skip(2).limit(5).toArray().then((docs) => { console.log(docs); }).catch((err) => { console.log(err); }).finally(() => { client.close(); }); }); ``` 該示例從`cars`集合中讀取,跳過前兩個文檔,并將輸出限制為五個文檔。 ```js db.collection('cars').find({}).skip(2).limit(5).toArray().then((docs) => { ``` `skip()`方法跳過前兩個文檔,`limit()`方法將輸出限制為五個文檔。 ```js $ node skip_limit.js [ { _id: 5d03e40f36943362cffc84a9, name: 'Skoda', price: 9000 }, { _id: 5d03e41336943362cffc84aa, name: 'Volvo', price: 29000 }, { _id: 5d03e41936943362cffc84ab, name: 'Bentley', price: 350000 }, { _id: 5d03e41e36943362cffc84ac, name: 'Citroen', price: 21000 }, { _id: 5d03e42236943362cffc84ad, name: 'Hummer', price: 41400 } ] ``` 這是示例的輸出。 ## MongoDB 聚合 聚合計算集合中數據的聚合值。 `sum_all_cars.js` ```js const mongo = require('mongodb'); const MongoClient = mongo.MongoClient; const url = 'mongodb://localhost:27017'; MongoClient.connect(url, { useNewUrlParser: true }, (err, client) => { if (err) throw err; const db = client.db("testdb"); let myagr = [{$group: {_id: 1, all: { $sum: "$price" } }}]; db.collection('cars').aggregate(myagr).toArray().then((sum) => { console.log(sum); }).catch((err) => { console.log(err); }).finally(() => { client.close(); }); }); ``` 該示例計算集合中所有汽車的價格。 ```js let myagr = [{$group: {_id: 1, all: { $sum: "$price" } }}]; ``` `$sum`運算符計算并返回數值的總和。 `$group`運算符通過指定的標識符表達式對輸入文檔進行分組,并將累加器表達式(如果指定)應用于每個組。 ```js db.collection('cars').aggregate(myagr).toArray().then((sum) => { ``` `aggregate()`函數將聚合操作應用于`cars`集合。 ```js $ node sum_all_cars.js [ { _id: 1, all: 581769 } ] ``` 所有價格的總和是 581,769。 我們可以使用`$match`運算符來選擇要匯總的特定汽車。 `sum_two_cars.js` ```js const mongo = require('mongodb'); const MongoClient = mongo.MongoClient; const url = 'mongodb://localhost:27017'; MongoClient.connect(url, { useNewUrlParser: true }, (err, client) => { if (err) throw err; const db = client.db("testdb"); let myagr = [ { $match: { $or: [{ name: "Audi" }, { name: "Volvo" }] } }, { $group: { _id: 1, sum2cars: { $sum: "$price" } } } ]; db.collection('cars').aggregate(myagr).toArray().then((sum) => { console.log(sum); }).catch((err) => { console.log(err); }).finally(() => { client.close(); }); }); ``` 該示例計算奧迪和沃爾沃汽車的價格總和。 ```js let myagr = [ { $match: { $or: [{ name: "Audi" }, { name: "Volvo" }] } }, { $group: { _id: 1, sum2cars: { $sum: "$price" } } } ]; ``` 該表達式使用`$match`,`$or`,`$group`和`$sum`運算符執行任務。 ```js $ node sum_two_cars.js [ { _id: 1, sum2cars: 81642 } ] ``` 兩輛車的價格之和為 81,642。 ## MongoDB `insertOne` `insertOne()`方法將單個文檔插入到集合中。 `insert_one.js` ```js const mongo = require('mongodb'); const MongoClient = mongo.MongoClient; const ObjectID = mongo.ObjectID; const url = 'mongodb://localhost:27017'; MongoClient.connect(url, { useNewUrlParser: true }, (err, client) => { if (err) throw err; const db = client.db("testdb"); let doc = {_id: new ObjectID(), name: "Toyota", price: 37600 }; db.collection('cars').insertOne(doc).then((doc) => { console.log('Car inserted') console.log(doc); }).catch((err) => { console.log(err); }).finally(() => { client.close(); }); }); ``` 該示例將一輛汽車插入`cars`集合。 ```js let doc = {_id: new ObjectID(), name: "Toyota", price: 37600 }; ``` 這是要插入的文檔。 使用`ObjectID`生成一個新的 ID。 ```js db.collection('cars').insertOne(doc).then((doc) => { ``` `insertOne()`函數將文檔插入到集合中。 ```js > db.cars.find({name:'Toyota'}) { "_id" : ObjectId("5d03d4321f9c262a50e671ee"), "name" : "Toyota", "price" : 37600 } ``` 我們用`mongo`工具確認插入。 ## MongoDB `insertMany` `insertMany()`函數可將多個文檔插入一個集合中。 `insert_many.js` ```js const mongo = require('mongodb'); const MongoClient = mongo.MongoClient; const ObjectID = mongo.ObjectID; const url = 'mongodb://localhost:27017'; MongoClient.connect(url, { useNewUrlParser: true }, (err, client) => { if (err) throw err; const db = client.db("testdb"); let collection = db.collection('continents'); let continents = [ { _id: new ObjectID(), name: "Africa" }, { _id: new ObjectID(), name: "America" }, { _id: new ObjectID(), name: "Europe" }, { _id: new ObjectID(), name: "Asia" }, { _id: new ObjectID(), name: "Australia" }, { _id: new ObjectID(), name: "Antarctica" } ]; collection.insertMany(continents).then(result => { console.log("documents inserted into the collection"); }).catch((err) => { console.log(err); }).finally(() => { client.close(); }); }); ``` 該示例創建一個`continents`集合并將六個文檔插入其中。 ```js let collection = db.collection('continents'); ``` `collection()`方法檢索集合; 如果集合不存在,則會創建它。 ```js let continents = [ { _id: new ObjectID(), name: "Africa" }, { _id: new ObjectID(), name: "America" }, { _id: new ObjectID(), name: "Europe" }, { _id: new ObjectID(), name: "Asia" }, { _id: new ObjectID(), name: "Australia" }, { _id: new ObjectID(), name: "Antarctica" } ]; ``` 這是要插入新集合的六個記錄的數組。 `ObjectID()`創建一個新的 ObjectID,這是用于標識文檔的唯一值,而不是整數。 ```js collection.insertMany(continents).then(result => { console.log("documents inserted into the collection"); }).catch((err) => { console.log(err); }).finally(() => { client.close(); }); ``` `insertMany()`方法將文檔數組插入`continents`集合。 ```js > db.continents.find() { "_id" : ObjectId("5cfcf97732fc4913748c9669"), "name" : "Africa" } { "_id" : ObjectId("5cfcf97732fc4913748c966a"), "name" : "America" } { "_id" : ObjectId("5cfcf97732fc4913748c966b"), "name" : "Europe" } { "_id" : ObjectId("5cfcf97732fc4913748c966c"), "name" : "Asia" } { "_id" : ObjectId("5cfcf97732fc4913748c966d"), "name" : "Australia" } { "_id" : ObjectId("5cfcf97732fc4913748c966e"), "name" : "Antarctica" } ``` `continents`集合已成功創建。 ## MongoDB `deleteOne` `deleteOne()`方法用于刪除文檔。 `delete_one.js` ```js const mongo = require('mongodb'); const MongoClient = mongo.MongoClient; const url = 'mongodb://localhost:27017'; MongoClient.connect(url, { useNewUrlParser: true }, (err, client) => { if (err) throw err; const db = client.db("testdb"); let query = { name: "Volkswagen" }; db.collection('cars').deleteOne(query).then((result) => { console.log('Car deleted'); console.log(result); }).catch((err) => { console.log(err); }).finally(() => { client.close(); }); }); ``` 該示例刪除文檔。 ```js let query = { name: "Volkswagen" }; db.collection('cars').deleteOne(query).then((result) => { ... ``` `deleteOne()`刪除`Volkswagen`的文檔。 ## MongoDB `updateOne` `updateOne()`函數用于更新文檔。 `update_one.js` ```js const mongo = require('mongodb'); const MongoClient = mongo.MongoClient; const url = 'mongodb://localhost:27017'; MongoClient.connect(url, { useNewUrlParser: true }, (err, client) => { if (err) throw err; const db = client.db("testdb"); let filQuery = { name: "Audi" }; let updateQuery = { $set: { "price": 52000 }}; db.collection('cars').updateOne(filQuery, updateQuery).then(result => { console.log('Car updated'); console.log(result); }).catch((err) => { console.log(err); }).finally(() => { client.close(); }); }); ``` 該示例更新了汽車的價格。 ```js let filQuery = { name: "Audi" }; let updateQuery = { $set: { "price": 52000 }}; db.collection('cars').updateOne(filQuery, updateQuery).then(result => { ``` 通過`updateOne()`方法將 Audi 的價格更改為 52,000。 `$set`運算符用于更改價格。 ```js > db.cars.find({name:'Audi'}) { "_id" : ObjectId("5cfcfc3438f62aaa09b52175"), "name" : "Audi", "price" : 52000 } ``` 我們使用`mongo`工具確認更改。 在本教程中,我們使用了 MongoDB 和 JavaScript。 列出[所有 JavaScript](/all/#js) 教程。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看