New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TS example - ENOENT ERROR #83
Comments
Hi @IrvingArmenta, I believe the path is wrong. Please notice, that you need to provide path to directory, not a single file, as in the example: https://github.com/pkosiec/mongo-seeding/tree/master/examples/import-data-ts Changing Let me know if that works. Cheers! |
Hello @pkosiec It seems to be working correctly now, thanks, however, I'm not sure but what I get is a collection called also, what I get in the Which is nothing like the data I'm trying to seed. {
"_id":ObjectId("5d5bc1bfd0f9dc3d2f862e4a"),
"IDENT_RE":"[a-zA-Z]\\w*",
"UNDERSCORE_IDENT_RE":"[a-zA-Z_]\\w*",
"NUMBER_RE":"\\b\\d+(\\.\\d+)?",
"C_NUMBER_RE":"(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)",
"BINARY_NUMBER_RE":"\\b(0b[01]+)",
"RE_STARTERS_RE":"!|!=|!==|%|%=|&|&&|&=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|<<|<<=|<=|<|===|==|=|>>>=|>>=|>=|>>>|>>|>|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~",
"BACKSLASH_ESCAPE":{
"begin":"\\\\[\\s\\S]",
"relevance":0
},
"APOS_STRING_MODE":{
"className":"string",
"begin":"'",
"end":"'",
"illegal":"\\n",
"contains":[
{
"begin":"\\\\[\\s\\S]",
"relevance":0
}
]
},
"QUOTE_STRING_MODE":{
"className":"string",
"begin":"\"",
"end":"\"",
"illegal":"\\n",
"contains":[
{
"begin":"\\\\[\\s\\S]",
"relevance":0
},
{
"className":"subst",
"begin":"\\\\[abfnrtv]\\|\\\\x[0-9a-fA-F]*\\\\\\|%[-+# *.0-9]*[dioxXucsfeEgGp]",
"relevance":0
}
]
},
"PHRASAL_WORDS_MODE":{
"begin":/\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|they|like|more)\b/
},
"C_LINE_COMMENT_MODE":{
"className":"comment",
"begin":"//",
"end":"$",
"contains":[
{
"begin":/\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|they|like|more)\b/
},
{
"className":"doctag",
"begin":"(?:TODO|FIXME|NOTE|BUG|XXX):",
"relevance":0
}
]
},
"C_BLOCK_COMMENT_MODE":{
"className":"comment",
"begin":"/\\*",
"end":"\\*/",
"contains":[
{
"begin":/\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|they|like|more)\b/
},
{
"className":"doctag",
"begin":"(?:TODO|FIXME|NOTE|BUG|XXX):",
"relevance":0
}
]
},
"HASH_COMMENT_MODE":{
"className":"comment",
"begin":"#",
"end":"$",
"contains":[
{
"begin":/\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|they|like|more)\b/
},
{
"className":"doctag",
"begin":"(?:TODO|FIXME|NOTE|BUG|XXX):",
"relevance":0
}
]
},
"NUMBER_MODE":{
"className":"number",
"begin":"\\b\\d+(\\.\\d+)?",
"relevance":0
},
"C_NUMBER_MODE":{
"className":"number",
"begin":"(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)",
"relevance":0
},
"BINARY_NUMBER_MODE":{
"className":"number",
"begin":"\\b(0b[01]+)",
"relevance":0
},
"CSS_NUMBER_MODE":{
"className":"number",
"begin":"\\b\\d+(\\.\\d+)?(%|em|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|px|deg|grad|rad|turn|s|ms|Hz|kHz|dpi|dpcm|dppx)?",
"relevance":0
},
"REGEXP_MODE":{
"className":"regexp",
"begin":/\//,
"end":/\/ [
gimuy
] */,
"illegal":/\n/,
"contains":[
{
"begin":"\\\\[\\s\\S]",
"relevance":0
},
{
"begin":/\ [
/,
"end":/\
] /,
"relevance":0,
"contains":[
{
"begin":"\\\\[\\s\\S]",
"relevance":0
}
]
}
]
},
"TITLE_MODE":{
"className":"title",
"begin":"[a-zA-Z]\\w*",
"relevance":0
},
"UNDERSCORE_TITLE_MODE":{
"className":"title",
"begin":"[a-zA-Z_]\\w*",
"relevance":0
},
"METHOD_GUARD":{
"begin":"\\.\\s*[a-zA-Z_]\\w*",
"relevance":0
}
} |
@IrvingArmenta It's because you have In this case, Mongo Seeding will import your data.ts file into collection You have to make sure that the input directory for Mongo Seeding contains only subdirectories, which has files to seed and their names are equal to your desired collection names. |
@pkosiec mongo-seeding Reading collections from /Users/irvingarmenta/Documents/dashb-mongo-ts/data-seed/import-data... +0ms
MongoSeedingError: SyntaxError: Unexpected token {
at wrapError (/Users/irvingarmenta/Documents/dashb-mongo-ts/data-seed/node_modules/mongo-seeding/src/index.ts:125:17)
at Seeder.readCollectionsFromPath (/Users/irvingarmenta/Documents/dashb-mongo-ts/data-seed/node_modules/mongo-seeding/src/index.ts:58:13)
at Object.<anonymous> (/Users/irvingarmenta/Documents/dashb-mongo-ts/data-seed/index.js:13:28)
at Module._compile (internal/modules/cjs/loader.js:777:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:788:10)
at Module.load (internal/modules/cjs/loader.js:643:32)
at Function.Module._load (internal/modules/cjs/loader.js:556:12)
at Function.Module.runMain (internal/modules/cjs/loader.js:840:10)
at internal/main/run_main_module.js:17:11 my npm script require('ts-node').register();
const path = require('path');
const { Seeder } = require('mongo-seeding');
const config = {
database: 'mongodb://localhost/dashb',
dropDatabase: true,
};
const seeder = new Seeder(config);
const collections = seeder.readCollectionsFromPath(
path.resolve('./data-seed/import-data'),
{
extensions: ['js', 'json', 'ts'],
transformers: [Seeder.Transformers.replaceDocumentIdWithUnderscoreId],
},
);
seeder
.import(collections)
.then(() => {
console.log('Success');
})
.catch(err => {
console.log('Error', err);
}); And the import { seedUser } from '../../../src/api';
import { getObjectId } from '../../helpers';
const names = ["Hanamichi", "Rukawa", "Haruko", "Akagi", "Mitsuki"];
const users: seedUser[] = names.map((name, i) => {
return {
id: getObjectId(name),
name,
email: `${name}@email.com`,
password: `password${i}`,
role: 'user'
}
});
export default users; |
I've just tried the TS example from this repository and it works well: https://github.com/pkosiec/mongo-seeding/tree/master/examples/import-data-ts |
Hi @IrvingArmenta, did you resolve the problem you had? Can I close this issue? |
Okay, I assume that your problem are solved. If you have any further questions, comment this thread or create another issue 🙂Cheers! |
I am not completely sure if this is an actual issue or is just that I'm missing something, but the npm script is not working, I keep getting
I have tried multiple file names on the
index.js
file but it keeps saying that it does not found the data fileThis is the index.js file:
and this is the
data.ts
file that is in the same directory asindex.js
I tried following the
ts
example, any ideas why I keep gettingENOENT
?my directory tree is:
data-seed has it's own
package.json
and also the main project folder too, has it's ownpackage.json
The text was updated successfully, but these errors were encountered: