小编For*_*er0的帖子

我的 express 应用程序中的 mongoose.connect 有名称: MongoParserError ,消息:“URI 格式错误,无法解析”

mongoose
    .connect(db,{ useNewUrlParser: true}) 
    .then(() => console.log("MongoDB conected ..."))
    .catch(err => console.log(err));
Run Code Online (Sandbox Code Playgroud)

上面提到的是我的代码,其中“db”是由 mLab 提供的我的数据库 URI

当我编写运行快速代码时,它会捕获错误并给出特定的错误消息:

URI 格式错误,无法解析

{ MongoError: URI malformed, cannot be parsed
    at parseConnectionString (/Users/dibs/Desktop/mern-ex/node_modules/mongodb-core/lib/uri_parser.js:207:21)
    at connect (/Users/dibs/Desktop/mern-ex/node_modules/mongodb/lib/operations/mongo_client_ops.js:179:3)
    at connectOp (/Users/dibs/Desktop/mern-ex/node_modules/mongodb/lib/operations/mongo_client_ops.js:283:3)
    at executeOperation (/Users/dibs/Desktop/mern-ex/node_modules/mongodb/lib/utils.js:420:24)
    at MongoClient.connect (/Users/dibs/Desktop/mern-ex/node_modules/mongodb/lib/mongo_client.js:168:10)
    at Promise (/Users/dibs/Desktop/mern-ex/node_modules/mongoose/lib/connection.js:487:12)
    at Promise (<anonymous>)
    at NativeConnection.Connection.openUri (/Users/dibs/Desktop/mern-ex/node_modules/mongoose/lib/connection.js:484:19)
    at Mongoose.connect (/Users/dibs/Desktop/mern-ex/node_modules/mongoose/lib/index.js:229:15)
    at Object.<anonymous> (/Users/dibs/Desktop/mern-ex/server.js:20:6)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Function.Module.runMain (module.js:605:10)
  name: 'MongoParseError',
  message: 'URI malformed, cannot …
Run Code Online (Sandbox Code Playgroud)

uri connect mongoose

12
推荐指数
3
解决办法
2万
查看次数

使用"部分"时为什么类级"不安全"修饰符不一致?

我已经注意到unsafe在类级别上对部分类使用修饰符时的某种行为,我希望得到一些澄清.

我一直在研究一个相当大的包装器,为了理智,我使用partial修饰符分割多个文件.包装器大量使用unsafe指针,因此我选择在类级别上简单地声明它以覆盖其中的所有内容.

public static unsafe partial class Ruby
{
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static VALUE CLASS_OF(VALUE obj) => ((RBasic*) obj)->klass;
}
Run Code Online (Sandbox Code Playgroud)

在另一个文件中:

public static unsafe partial class Ruby
{
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void* DATA_PTR(VALUE obj) => ((RData*) obj)->data;
}
Run Code Online (Sandbox Code Playgroud)

unsafe修改需要每个部分的声明,以使不安全的代码被"允许"和编译,这是可以理解的,我希望,对于部分类的类声明将需要完全匹配.

但是使用那个逻辑,我也被允许有另一个不是的文件unsafe:

[SuppressUnmanagedCodeSecurity]
public static partial class Ruby
{
    [DllImport(RUBY_LIBRARY, CallingConvention = CallingConvention.Cdecl)]
    public static extern VALUE rb_ivar_get(VALUE obj, ID name);
}
Run Code Online (Sandbox Code Playgroud)

在这里,我不使用unsafe修饰符,它是完全可以接受的(显然在这个文件中没有不安全的代码).

我是什么希望得到澄清为什么这允许.每个分类的类声明不应该完全匹配吗?改变/不包括任何其他类改性剂是不允许的,例如private,public,abstract等等,所以这是为什么好吗用unsafe …

c# unsafe

6
推荐指数
1
解决办法
127
查看次数

静态使用性能惩罚?

我很好奇在使用“典型”方式导入静态类与使用“典型”方式导入静态类和使用接收器显式调用方法之间是否存在任何运行时性能损失using,特别是在涉及相当大的类时。

例如,我当前的项目使用 OpenGL,其中每个 OpenGL 函数都绑定到类中的一个静态方法Gl。我选择保持此类中的命名约定与其本地对应项(即glClearis Gl.glClear)相同。

然后我像这样使用这个类:

using static OpenGL.Gl;

void SomeFunction()
{
    glClear();
    // etc, etc
}
Run Code Online (Sandbox Code Playgroud)

……与此相反……

using OpenGL;

void SomeFunction()
{
    Gl.glClear();
    // etc, etc
}
Run Code Online (Sandbox Code Playgroud)

撇开命名约定不谈,在这种情况下将如此多的符号导入当前上下文是否有任何运行时惩罚(因为Gl该类具有数百个静态方法和公共常量)?

我并不真正关心构建时间或 IDE 上提供智能感知的额外工作量,只关心编译后的最终结果。

我的感觉是它只是语法糖并产生相同的 IL 代码,但我不太精通阅读 IL 以自信地确定这一点。

c#

1
推荐指数
1
解决办法
60
查看次数

标签 统计

c# ×2

connect ×1

mongoose ×1

unsafe ×1

uri ×1