Skip to content

Releases: xpresserjs/xpress-mongo

Update Mongodb And Fix save twice bug.

26 Aug 04:11
Compare
Choose a tag to compare

Updated Packages

Updated mongodb to version 4.9.0

Save Twice Bug

An error occurs when you generate id and save twice for example

const user = User.make({}).generateId();

await user.save()
user.data.username = "changed"

await user.save() // ❌ will throw a duplicate id.

This has been fixed.

Updated Packages & Added Pagination data with frontend support.

03 Jul 19:17
Compare
Choose a tag to compare

MongoDB Package has been updated to 4.7.0.

Pagination types for backend and frontend usage are now available in a single file.

Paginated Type

import type {Paginated} from "xpress-mongo/src/types/pagination";

const users: Paginated<User> = await api.get('/path/to/paginated/resource');

users.total // Total results
users.perPage // Results per Page
users.page // current page
users.lastPage // last page
users.data // paginated data

Paginated Function

Paginated is also a function that returns typed default pagination data

import {Paginated} from "xpress-mongo/src/types/pagination";

const users = Paginated<User>();

// users will have default paginated data.

An example using vue

<script lang="ts" setup>
import {Paginated} from "xpress-mongo/src/types/pagination";

const users = ref(Paginated<User>());

// users will have default paginated data.
</script>

Updated mongodb and applied deprecated `count` changes

10 Mar 09:26
Compare
Choose a tag to compare

The new mongodb v 4.4.0 to be exact deprecated collection.count() but this won't be a breaking change for us as the new recommended countDocuments and estimatedDocumentCount has been applied.

Model.count(filter?, options?) // is same as native().countDocuments()
Model.countEstimated() // is same as native().estimatedDocumentCount()

It is recommended you use count when you have a query filter and countEstimated when you have none.

Nevertheless xpress-mongo's count uses countEstimated when no query is provided.

Added: sum & sumMany

10 Mar 08:57
Compare
Choose a tag to compare

Before now sum does the work of both single and multiple keys but this gets difficult when dealing with types and readability.

Old

// sum one key 
await Model.sum("fiat") // number
// sum multiple keys
await Model.sum(["fiat", "crypto"]) // {fiat: 200, crypto: 2.456}
// sum multiple fields with nick names 
await Model.sum({totalFiat: 'fiat', totalBitcoin: 'crypto'}) // {totalFiat: 200, totalBitcoin: 2.456}

New

Docs: https://xpresserjs.com/xpress-mongo/model.html#sum-async

// sum one key 
await Model.sum("fiat") // number
// sum multiple keys
const sum = await Model.sumMany(["fiat", "crypto"]) // {fiat: 200, crypto: 2.456}
// sum multiple fields with nick names 
const sum2 = await Model.sumMany({totalFiat: 'fiat', totalBitcoin: 'crypto'}) // {totalFiat: 200, totalBitcoin: 2.456}

With types support: sum and sum2 will be typed to have defined keys.

Upgraded packages and fixed uuid import issue

27 Jan 07:07
Compare
Choose a tag to compare

This Release fixes issue: #7

Reported by @Katalyst33

Refactored Typescript Pratices

23 Jan 09:54
Compare
Choose a tag to compare
  • Now using import instead of require, in preparation for when typescript fully supports ESM
  • Removed lodash as dependency since object-collection/lodash has it exported already.