Giter VIP home page Giter VIP logo

Comments (5)

zackyang000 avatar zackyang000 commented on September 1, 2024

Hi @tomerpar133 ,

When you use mongoDB which is NoSQL database for persistent data, the best practices is that define a complex type to do this.

In your example, you should:

server.resource('books', {
title: String,
price: Number
authors: {
  name: String
},
categories: [{
  name: String
}],
...
});

So, you maybe not necessary to use reference.

from node-odata.

tomerpar133 avatar tomerpar133 commented on September 1, 2024

Hi

I need to do other manipulations on authers and I need it in another document

Is therea way to reference a collection to another?

from node-odata.

zackyang000 avatar zackyang000 commented on September 1, 2024

Hi,

Unfortunately, it's not support reference, at least for now. You have to query again, which you want to reference's resource (The worst case you should query N+1 times).

You can save resource's id in another resource. For example:

server.resource('books', {
  title: String,
  price: Number
});

server.resource('authors', {
  name: String,
  books: [{ String }]  // <--- book's id
});

Once again, good way is that define a complex type, even need redundant data.

GOOD: easy to query, and faster.
BAD: need update multiple resources when you want to modify it.

server.resource('books', {
  title: String,
  price: Number,
  author: {
    name: String
  }
});

server.resource('authors', {
  name: String,
  books: [{
    title: String,
    price: Number
  }]
});

from node-odata.

tomerpar133 avatar tomerpar133 commented on September 1, 2024

Ok
Thank you

from node-odata.

bastianbin avatar bastianbin commented on September 1, 2024

Hi, is there any work invested into enabling this? Especially with complex data with lots of data this would be helpful since data modeling does reduce the size of the db. I understand the workaround but using the reference might make it easier to automatically generate code to consume the api.

from node-odata.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.