Skip to content

Removing docs in a linked collection leads to <linkedId>: null in another linked collection #450

@Twisterking

Description

@Twisterking

Hello @theodorDiaconu !

You might remember me as the "bit annoying guy with way too many Grapher questions" some months/years ago! 😁

So I have been using grapher in production successfully for many years now and still am very happy.

For months I have had the problem that in some collections more and more documents popped up with <linkedCollId>: null, rendering them simply unuseable.

I have the following case:

I have 2 collections: items and prices.

items Links:

Items.addLinks({
  prices: {
    collection: Prices,
    inversedBy: 'item'
  }
});

prices links:

Prices.addLinks({
  item: {
    type: 'one',
    collection: Items,
    field: 'itemId'
  }
});

In one of the most important functions of my app, I sometimes have to delete many items documents. At some point in this function I have an array with itemIds which should be deleted.

if (toBeRemovedIds && toBeRemovedIds.length > 0) {

  // ALWAYS remove the pricedata
  let removePricesQuery = Object.assign({ itemId: { $in: toBeRemovedIds } }, priceFindAssign);
  try {
    const removedNum = await Prices.remove(removePricesQuery);
    if (removedNum) result.PricesRemoveResult = { ok: true, removed: removedNum };
  } catch (err) {
    console.error('Prices.remove ERROR:', err);
  }

  // Actually remove the items
  try {
    const removedNum = await Items.remove({ _id: { $in: toBeRemovedIds } });
    if (removedNum) {
      result.ItemsRemoveResult = { ok: true, removed: removedNum, removedItemRefs };
    }
  } catch (err) {
    console.error('Items.remove ERROR:', err);
  }

}

So I FIRST deleted the linked prices, THEN I delete the items themselves.

This does NOT SEEM TO WORK. The above code results in many documents in the prices collection with itemId: null!

I really need some input here. This is just an example, ALL of my linked collections are full of documents with<myLinkedIdHere>: null.

Any input is appreciated!

Cheers, Patrick

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions