question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[types] Model.create dosnt return array

See original GitHub issue

Do you want to request a feature or report a bug? type-bug

What is the current behavior? await SomeModel.create([doc1, doc2]) dosnt return an array

If the current behavior is a bug, please provide the steps to reproduce. code used:

// NodeJS: 14.15.1
// MongoDB: 4.2-bionic (Docker)
// import { getModelForClass, prop } from "@typegoose/typegoose"; // @typegoose/typegoose@7.4.5
import * as mongoose from "mongoose"; // mongoose@5.11.12

interface ISomeModel extends mongoose.Document {
  param1: string,
  param2: number,
}

const SomeSchema = new mongoose.Schema({ param1: String, param2: Number });
const SomeModel = mongoose.model<ISomeModel>("SomeModel", SomeSchema);

(async () => {
  await mongoose.connect(`mongodb://localhost:27017/`, { useNewUrlParser: true, dbName: "verifyMASTER", useCreateIndex: true, useUnifiedTopology: true });

  const [...docs] = await SomeModel.create([{ param1: "Hello", param2: 1 }]);
  const doc = await SomeModel.create({});


  await mongoose.disconnect();
})();
{
    "compileOnSave": true,
    "typeAcquisition": {
        "enable": true
    },
    "compilerOptions": {
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "declarationMap": true,
        "outDir": "lib",
        "moduleResolution": "node",
        "target": "es6",
        "module": "commonjs",
        "newLine": "LF",
        "sourceMap": true,
        "removeComments": true,
        "strict": true,
        "allowUnreachableCode": false,
        "pretty": true,
        "declaration": true,
        "lib": [
            "esnext"
        ]
    },
    "include": [
        "src/**/*"
    ]
}

What is the expected behavior? that await SomeModel.create([doc1,doc2]) returns an array

What are the versions of Node.js, Mongoose and MongoDB you are using? mongoose 5.11.12 typescript 4.1.3

would have provided an pr, but didnt find an fix yet

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
imduchycommented, Jan 17, 2021

@hasezoey I’m not sure, hah. I also tried to play around with this but didn’t figure it out.

https://github.com/Automattic/mongoose/blob/c44d521e18d292817a37c9c1623721da52a249f6/index.d.ts#L635

@vkarpov15 shouldn’t the above overload return an array? I can create a PR if so…

create<Z = T | DocumentDefinition<T>>(...docs: Array<Z>): Promise<Array<T>>;
0reactions
hasezoeycommented, Feb 5, 2021

actual issue should get fixed by #9890 (didnt test it yet)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mongoose find method does not return array - Stack Overflow
That is because, type of array is object, and not Array. let arr = []; let arr2 = [{ a: 1 }, {...
Read more >
Eloquent ORM - Laravel - The PHP Framework For Web Artisans
You may also use the create method to save a new model in a single line. The inserted model instance will be returned...
Read more >
Objects - Manual - PHP
CAUTION: "Arrays convert to an object with properties named by keys, and corresponding values". This is ALWAYS true, which means that even numeric...
Read more >
Django Tutorial Part 3: Using models - Learn web development
Within each of the boxes, you can see the model name, the field names, and types, and also the methods and their return...
Read more >
Documentation: 15: 8.15. Arrays - PostgreSQL
The above command will create a table named sal_emp with a column of type ... is returned if a subscript is outside the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found