我一直在尝试获取大于提供的 _id 的记录 代码在下面
filter = bson.M{"_id": bson.M{"$gt": "5c1760b4bd421c09e0f3140c"}}
cur, err := collection.Find(ctx, filter, &options)
但是iam总是获取空值。 我想我需要将该ID转换为对象ID 但是我不确定在最新版本中该怎么做 预测中显示了一个bson.TypeObjectID。有人可以提供一些详细信息吗?谢谢
答案 0 :(得分:2)
您需要将class VariantGroupComplexProductType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
// Render the drop downs based on the Parsed variant group
$builder
->add( 'label' )
// Rendering of the drop down must be done after the previous form data is available
->addEventListener(FormEvents::PRE_SET_DATA, [$this, 'preSetData']);
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults( [
'data_class' => VariantGroup::class,
] );
}
public function preSetData(FormEvent $event)
{
$form = $event->getForm();
/** @var VariantGroup $child */
$child = $event->getData();
$form
->add('variants', EntityType::class, array(
'class' => Variant::class,
'by_reference' => true,
'query_builder' => function (EntityRepository $er) use ( $child ) {
return $er->createQueryBuilder('u')
->where('u.variant_group = :variant_group')
->setParameter('variant_group', $child )
->orderBy('u.label', 'DESC');
},
'choice_label' => 'label',
));
}
}
与ObjectID
进行比较。您正在做的是将ObjectID
与ObjectID
进行比较。
string