TransWikia.com

How to add field description to mongodb collection

Stack Overflow Asked on November 29, 2021

We have large no of fields in each collection.

To reduce json size we have added short names/ acronym to most of the fields from collection.

1 Example – We used "ECA" field name instead of EmployeeCurrentAddress

I am new to mongodb.

Can we add description to field/column names in mongodb ?

It’s difficult remember all fields names meaning/description.

Mongodb compass showing field name, value & type.

Whenever there will be new field xyz added, we want to add

xyz – string – XYZ column description.

We are planning to add field description to each field from each collection.

We can prepare document(word/excel) for each collection with meaning of each field/column, but it’s painful to other/new developer to look into doc everytime.

How can I script this so when my NoSQL scripts create the fields, a description for the fields is also added/updated?

How can we add description to each field/column in mongodb ?

It will be helpful for to know meaning of specific column.

  1. Some mongodb command to get metadata of field
  2. Or On mouse over of field in mongo client we can see meaning of field name

One Answer

When you create a POCO class for MongoDB. That is the place where you can make those description. It is called Data annotations.

https://docs.microsoft.com/en-us/ef/ef6/modeling/code-first/data-annotations

public class Customer { public string Name { get; set; } public string Address { get; set; } } The default JSON representation of this POCO will be:

{ "Name" : "Elvis" , "Address" : "Graceland" }

The POCO will be saved in the BSON format but the above JSON helps visualise the binary source. If the POCO has some sequence of objects, e.g.:

You can now create description/annotations field on top of it.

[Column("BlogDescription", TypeName="ntext")] public String Description {get;set;}

Answered by Jin Thakur on November 29, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP