0

If I have a collection and put some data in it, just like

    {
        "_id" : ObjectId("xxxxxxxxxxxxxxxxxxxxx"),
        "name" : "Tom",
        "age" : 22,
        "job":"engineer"
    }

when I use Mysql ,I can use command 'desc table' to list all fields ,so when I switch to mongodb ,how can I list all field what I expected like '_id,name,age,job'

Jazib
  • 1,343
  • 13
  • 27
happy_foo
  • 1
  • 1
  • Does this answer your question? [Get names of all keys in the collection](https://stackoverflow.com/questions/2298870/get-names-of-all-keys-in-the-collection) , In that link check @styvane's answer – whoami - fakeFaceTrueSoul Mar 11 '20 at 15:03

2 Answers2

0
db.collection.insertOne({"name" : "Tom","age" : 22,"job":"engineer"})

this is the simple query in command prompt run it, it will add the data exactly the above ....

Jazib
  • 1,343
  • 13
  • 27
Venky Kick
  • 21
  • 4
0

That's one of the major conceptional difference between relational databases like MySQL and NoSQL databases as MongoDB.

In relational databases you have tables with columns. Each record in such table has these columns.

In NoSQL databases you have just documents and (by default) these documents do not enforce any particular structure. Thus there is no way to retrieve the field structure of such documents as in principle it can be different for each document.

Wernfried Domscheit
  • 54,457
  • 9
  • 76
  • 110