Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Form generation from Mongoose Schema object?

I was looking at trying to generate a form based on a Mongoose schema definition. I was having trouble finding where the schema info is tucked away. Where is the path type info etc kept in the object?

Or better, has anyone tried to do this already? I'm using Jade but something that pumps out HTML would also be good.

like image 889
CpILL Avatar asked Mar 19 '12 04:03

CpILL


People also ask

Which property of Mongoose will help us create a model object?

By default, Mongoose adds an _id property to your schemas. const schema = new Schema(); schema.path('_id'); // ObjectId { ... } When you create a new document with the automatically added _id property, Mongoose creates a new _id of type ObjectId to your document.

What does $Set do in Mongoose?

The $set operator replaces the value of a field with the specified value. The $set operator expression has the following form: { $set: { <field1>: <value1>, ... } } To specify a <field> in an embedded document or in an array, use dot notation.

How does Mongoose store objects?

Working with save() save() is a method on a Mongoose document. The save() method is asynchronous, so it returns a promise that you can await on. When you create an instance of a Mongoose model using new , calling save() makes Mongoose insert a new document.

What is the type of Mongoose object ID?

By default, MongoDB creates an _id property on every document that's of type ObjectId. Many other databases use a numeric id property by default, but in MongoDB and Mongoose, ids are objects by default.


2 Answers

My little project creates complete CRUD for a mongoose schema. Its a little rough but might be useful. https://github.com/jspears/bobamo

It is very client side though, all the forms are generated (they can be overriden with static versions if it is not what you need). That is it doesn't use jade, but it does use underscore template on the client and jqtpl on the server to generate the javascript that makes the form.

Wow that was really unclear... The browser talks to the server via JSON/REST it loads this into an all javascript front end. This front end is generated on the node server on demand, to the client. So it easy to modify, and relatively cleanly sepeartes the data from the view.

like image 140
speajus Avatar answered Oct 21 '22 14:10

speajus


I can recommend checking out Formage (npm: formage)

https://github.com/Empeeric/formage

You can get good ideas from this project.

like image 42
Qorbani Avatar answered Oct 21 '22 15:10

Qorbani