Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9146253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:42:22+00:00 2026-06-17T10:42:22+00:00

Consider, Mongoose schema: var schema_obj = new Schema({ field1: String, field2: String, ……… });

  • 0

Consider, Mongoose schema:

var schema_obj = new Schema({
    field1: String,
    field2: String, .........
});

JSON document, like:

var json_obj = {
field1: 'value', 
field2 : 'val2', 
............
};

For saving I call method, like

var Model_obj = mongoose.model('model_name', schema_object);
var document_obj = new Model_obj(json_obj);
document_obj.save(function(err,data){/*some logic after save*/});

Now my question is: Why should I create a json_obj.
When I already have a schema object in my hand, which already has all the fields (field1, field2). If I just want to give values for those fields why should I create json by writing all the field name again?

If I have n number of fields this becomes a overhead to write all fields again. Is there any way to avoid this overhead?

Something like I get a empty JSON object out of my defined mongoose schema, then just proceed by assigning only values?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T10:42:24+00:00Added an answer on June 17, 2026 at 10:42 am

    What kind of API are you looking for? You can set properties on a model instance and save it. But I’m not sure if I understand why

    var thing = new Thing();
    thing.name = "The Name";
    thing.priceInCents = 1999;
    thing.numAvailable = 10;
    thing.save();
    

    is easier than

    var thing = new Thing({name: 'The name', priceInCents: 1999, numAvailable: 10});
    thing.save();
    

    In a web app, this becomes something like

    app.post('/things', function(req, res) {
      var thing = new Thing(req.body.thing);
      thing.save(function() { ... });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

consider the following code: window.stage = bonsai.run(document.getElementById('stage'), { code: function() { var circle; circle
Consider the following snippet of code: foreach (var setting in RequiredSettings) { try {
Consider a markup such as <select id=blah> <option value=3>Some text</option> <option value=4>Some text</option> <option
Consider two forms: form1 and form2 form1 calls form2 : form2 frm = new
Consider this: string test = ""; somestring.ToList().Take(50).Select( delegate(char x) { test += x; return
Consider this class: public class TestMap extends HashMap<String, Float> { public static void main(String[]
Consider the following code: Class Demo { Person person = new Person(foo); // assume
Consider this layout (pulled from here ): I'd like to understand the principles behind
Consider the following (rather complicated) query expressed in this JSON object: { name: Kindle
Consider the following situation.. $var = 'Lots of information'; function go($var) { // Do

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.