Closed sheleoni closed 9 months ago
The latest updates on your projects. Learn more about Vercel for Git ↗︎
Name | Status | Preview | Comments | Updated (UTC) |
---|---|---|---|---|
icecream-sheleoni-com | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Dec 13, 2023 10:57am |
Problem at: bd141d1
tideLevel is being stored as ObjectId on mongodb, not sure how to go about this.
Tried changing tideLevelSchema to
tideLevel: {
type: Map,
of: Number
}
but it did not work.
Also tried using a mixed schema
import mongoose, { Schema, model, models } from "mongoose";
export const userTideLevelSchema = new Schema({
// kana: String,
// tideLevel: Number,
type: mongoose.Schema.Types.Mixed
},
);
but it did not work.
This may be related:
Maybe this will help:
OK it's probably a schema thing, eba40c0 seems to shed us some light! 😢
Achieved (on mongoDB):
By trying out:
const clonedTideLevel = { kana: "ら", level: 3 };
and
export const userTideLevelSchema = new Schema({
kana: String,
level: Number,
}
);
I guess my ultimate question is: store a object with many keys mongoDB or as array?
I think we may have to get use to the fact that frontend data structure can be different from backend data structures.
E.g. in the frontend, tideLevel.js
:
const tideLevel =
{
// hiragana
"あ": 5,
"い": 4,
"う": 3,
"え": 2,
"お": 1,
"か": 5, ...and so on
In the backend:
[{ kana: 'あ’, tideLevel: 5, _id: ObjectId('someId')
}, { and so on }]
need to see if it's a code problem or not before moving on to this conclusion
Objective:
Issue:
but when we send this object as-is to mongoDB, the object is not recognised and only an
_id
is added to the document. (ref)Solution
Settled for now, documented here.