markdown 挑战11:Mongo基础知识

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 挑战11:Mongo基础知识相关的知识,希望对你有一定的参考价值。

For this challenge you will run through a set of CRUD operation with Mongo.

### Getting Started

To get started, you will need to create a `noteful` database with a `notes` collection and populate it with documents.

- Copy the [contents of this gist](https://gist.githubusercontent.com/cklanac/1eb17fc0d0e1388b3a5ca7fcbbc9f90c/raw/77f4845a600fdceb8df31055e5bbf635c653746c/notes.json) into a JSON file and import it using `mongoimport`. Note, the data in ths gist is formatted as a proper JSON array of objects, so the import process is slightly different that the Restaurants data used earlier. Below is the `mongoimport` command with `--jsonArray` flag.

```sh
mongoimport -d noteful -c notes --drop --jsonArray --file ~/<path-to-unzipped-data-file>
```

Next, create a `mongo-queries.js` file. In the file, create the queries to solve each of the following:

### Exercises

1. Write a MongoDB query to display all the documents in the collection notes.

2. Write a MongoDB query to display all the documents in the collection notes and format the results to be 'pretty'.

3. Write a MongoDB query to display the fields title and content for all the documents in the collection notes.

4. Write a MongoDB query to display the fields title and content but exclude the field _id for all the documents in the collection notes.

5. Write a MongoDB query to display only the title field for all the documents in the collection notes and sort the results by _id in descending order.

6. Write a MongoDB query to display all the documents from the collection notes which contain the title '5 life lessons learned from cats'.

7. Write a MongoDB query to display the first 5 documents from the collection notes.

8. Write a MongoDB query to display the next 5 documents from the collection notes after skipping the first 5.

9. Write a MongoDB query to display the total number of documents in the collection notes.

10. Write a MongoDB query to display the documents from the collection notes which have an _id that is greater than "000000000000000000000007".

11. Write a MongoDB query to display the documents from the collection notes which have an _id which is greater than or equal to "000000000000000000000009" but less than or equal to "000000000000000000000017".

12. Write a MongoDB query to display the documents from the collection notes which have an _id which is less than or equal to "000000000000000000000007".

13. Write a MongoDB query to display only one document from the collection notes.

14. Write a MongoDB query to display only the title of one document from the collection notes (_id can be included).

15. Write a MongoDB query to display only the title of one document from the collection notes (_id excluded).

16. Write a MongoDB query to insert one document into the collection notes. The title and content fields can be whatever you like.

17. Write a MongoDB query to insert two note documents into the collection notes. The title and content fields can be whatever you like.

18. Write a MongoDB query to modify the title and content fields of the document from the collection notes with _id "000000000000000000000003". Change the title and content to be whatever you like.

19. Write a MongoDB query to modify only the title field of the document from the collection notes with _id "000000000000000000000007". The content field should remain unchanged.

20. Write a MongoDB query to modify the title and content fields of all the documents in the collection notes that have an _id field greater than "000000000000000000000014".

21. Write a MongoDB query to remove only the title field from the document in the collection notes with _id "000000000000000000000008".

22. Write a MongoDB query to remove the content fields from all documents in the collection notes with _id less than or equal to "000000000000000000000006".

23. Write a MongoDB query to remove the title fields from all documents in the collection notes with _id less than or equal to "000000000000000000000003".

24. Write a MongoDB query to remove the document from the collection notes that has an _id "000000000000000000000017".

25. Write a MongoDB query to remove the documents from the collection notes that have an _id which is not less than "000000000000000000000018".

26. Write a MongoDB query to remove the documents from the collection notes that have an _id which is greater than or equal to "000000000000000000000013" and contain the string 'dogs' in the title.

27. Write a MongoDB query to display all the documents from the collection notes which do not have a title field.

28. Write a MongoDB query to remove all the documents from the collection notes which contain the string 'cat' in the title but not the string 'the'.

29. Write a MongoDB query to display all the documents from the collection notes that have a title field which does not contain the string 'dogs' and does contain a title field.

以上是关于markdown 挑战11:Mongo基础知识的主要内容,如果未能解决你的问题,请参考以下文章

markdown 挑战11 - Vue简介

markdown [mongo auth]创建用户,角色等#mongo

markdown Mongo常用语句

markdown Mongo命令

markdown Mongo备忘单

markdown Mongo备忘单